On Sat, Mar 26, 2005 at 11:57:48PM -0500, Uri Guttman wrote: : >>>>> "LW" == Larry Wall <[EMAIL PROTECTED]> writes: : : LW> That being said, in Perl 5, if you say : : LW> @a = undef; : : LW> you don't get an undefined array. I'd like to make undef smart enough : LW> about list contexts that @a actually does end up undefined in Perl 6. : LW> That is, in scalar context, undef is a scalar value as in Perl 5, but : LW> in Perl 6, undef in list context means "there isn't anything here if : LW> you try to look for it", so it's more like () in Perl 5, except that : LW> it also undefines the array if it's the only thing in the array. : : then how would you assign undef to the only element of the array? would this : be needed: : : @a = ( undef ) ; # same as p5? : : vs. : @a = undef ; # like undef @a in p5?
Those would do the same thing under the current proposal, since they're both in list context. If you really, really want a scalar undef value in list context, you could always say @a = scalar(undef); : i have always railed against undef on aggregates as it leads to using : defined on them which is not the same as checking if an aggregate has : any elements. i see that often in newbie code. Well, let's not confuse Perl 5's shortcomings with Perl 6's. I think we should fix the problem by making undef work a little more like the newbie expects, which is context dependent. : in fact i would like to : stop allowing undef as a function with args and have it only return a : scalar undef value. there should be a different op to truly make an : aggregate undefined (and i still don't see a need for that, emptying it : is all that i ever think is needed). We could certainly split out a separate undefine() function. We could even give it an optional argument that says *why* it's undefined, turning it into an unthrown exception, basically. We could use such a function to create interesting values of undef that are context sensitive. : in my world undef is a scalar value and nothing else. how do you see it : in p6? undef is not a scalar value, it is the explicit *absence* of a value where you expected one. In Perl 6, undef is the Bearer of Bad News. If you merely want undef for a scalar placeholder without negative connotations, I'd suggest something like class Empty {} my $nada = new Empty; instead. And $nada is the same length as undef. $X would be even shorter. On the other hand, Perl 6 is consistently returning booleans as 0 and 1 rather than "" and 1, so it's likely that constant 0 and 1 can be stored in "less than a bit", as it were. So there might even be some kind of zero type that's essentially a value that's always 0, and takes no room to store at all. That might serve as a pretty good neutral placeholder. Larry