On Fri, Jan 13, 2006 at 10:33:23PM +0000, Luke Palmer wrote: : In perl 5: : : my @a = (1,2,3); : delete $a; : print exists $a; : : This is false, whereas $a and $a do exist. This is creepy. Not : only is it creepy, it raises a whole bunch of questions with : nontrivial answers: : : * does [EMAIL PROTECTED] include nonexistent elements? : * does map iterate over nonexistent elements?
The answer in Perl 5 is "yes", but Perl 6 doesn't have to have the same default. In many ways you'd want a sparse array to behave more like a hash. But then how often do you ask a hash only for its values? Whatever the answer, it probably has to apply to my @a; @a = '1'; @a = '3'; print exists $a; as well as the explicit delete case. Are we going to pitch an exception for writing beyond the end of an array? That seems a bit anti-Perlish. : * how do you store nonexistence for native packed arrays Well, packed arrays aren't the default, but obviously if you want to support sparseness in packed arrays you'd have to do something like one of: 1) Distinguish a value that doesn't "exist" (NaN, for instance). 2) Record the existence out-of-band, say, in a bitmap. 3) Only store "runs" of existing packed data. Approach #2 has the advantage that you can track definedness along with existence for native types that don't contain the Maybe concept. However, I think our default stance was that the user probably uses native types because they want things to run fast, so it's okay to pitch an exception if you ask a native type to remember something it's incapable of remembering. But "smart" native types are still a possibility. : And, what I always say, if the proper abstractions are being used, : then all decisions become obvious truths. Since the answers to these : are not obvious truths, proper abstractions must not be in use. Yeah, well... Abstractions are complete hypocrites--they make other things obvious while refusing to be obvious themselves. : Anyway, I want this behavior to die. Maybe we should get rid of : .delete() on arrays, or maybe we should equate it with : .splice($idx,1). Or maybe we support sparse arrays as one container type. I actually used a crowbar last week. It wasn't pretty, but it got the job done. Well, okay, it got the job started...I still have a hole in my living room wall, but my chief interest at the time was to make sure my house wasn't going to burn down. That's about as much abstraction as you could wish for in real life. Larry