Michael Lazzaro wrote:

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'.
If C<undef> is a valid value for a cell, then I should be able to store it. I think that C<delete> would better convey the intent -- it would also help with the behavior of negative indexes.



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?
Definitely 0. Definitely 0. DEFINITELY ZERO.

@a[0] = undef;
@a[0]; # 0, or 5?

STRAWMAN ANSWER: 5, in both cases. So don't do that unless you mean it.
0: see (2a)

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.
sounds good. But we wqant to ensure that the default value can actually be a closure -- i.e. its not a C<default> if we execute it.


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.
Yes


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.
Should follow (3a): the generator can through the exception if desired.

Now, what about @a[2.5]: can my generator do interpolation?


Dave.
--
http://dave.whipp.name

Reply via email to