On Tue, Jan 28, 2003 at 11:15:26AM -0800, Michael Lazzaro wrote:
> 2) Assume the default value is a simple value, e.g. 'foo'.
>
> my @a is Array( default => 'foo' );
> @a[5] = 'bar';
>
> @a[4]; # 'foo'
> @a[5]; # 'bar'
> @a[6]; # 'foo'
>
> @a[-1]; # 'bar' *NOTE!*
Um ... why?
> 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'.
This makes sense to me.
> 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, definitely. @a[0] was defined so the default doesn't come into
play.
> @a[0] = undef;
> @a[0]; # 0, or 5?
5, because undefined things get 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.
Heh. I'd want different syntax for default values vs. default
generators though.
> 3a) NOTE that closure-based defaults effectively render the array
> infinite. Therefore -- If the requested index is negative, what
> happens?
>
> @a[-5];
>
> STRAWMAN ANSWER: The closure just gets a negative number as
> the requested index. It's up to you to make it work, if you
> want it to.
Sounds good to me.
> 3b) Does an "infinite" array still get an exception thrown when trying
> to access an infinite [Inf] or [-Inf] index?
>
> STRAWMAN ANSWER: Yes, it does.
Based on 3a, I'd say that the closure should get Inf (or -Inf) and
do the appropriate thing. In your example above, Inf**2 would be Inf,
so the closure would return Inf (assuming I've got the Inf math right
and it's not really NaN)
-Scott
--
Jonathan Scott Duff
[EMAIL PROTECTED]