Michael Lazzaro said: > > There has been discussion of allowing a "default" value for array cells > -- that is, one aside from C<undef> or whatever the type-specific > default is. Questions, in order of increased evilness:
1 and 2 seem fine to me. > 2a) When a cell is explicitly re-undefined, does the default value take > effect? > > my @a is Array( default => 'foo' ) = (1,2,3); > > @a[1] = undef; > @a[1]; # undef, or 'foo'? > > STRAWMAN ANSWER: 'foo'. Seems right to me. Anything else would be very confusing, I think. > 2b) Primitive-typed arrays: Given the behavior of (2a), and the fact > that primitive-typed arrays can't store undef, what happens here? > > my int @a is Array( default => 5 ); > > @a[0] = 0; > @a[0]; # 0, or 5? 0. Being unable to store 0 would seem to be a major limitation. > @a[0] = undef; > @a[0]; # 0, or 5? An exception or 5. Maybe undefining an element could always set it to the default value. > 3) Can the default value be a closure, based on index location? > > my @a is Array( default => { $_ ** 2 }); > > STRAWMAN ANSWER: Yes, because it's cool. No, because it's unnecessary. You can always do my $value = @a[$x] //= $x ** 2; or skip the = depending on how you are trading memory / speed. Yes, I know that just about everything is unnecessary to someone. To me, default values as a whole seem a little unnecessary, in fact. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net