Aaron Sherman wrote:
> Someone's missing something, and I sure hope it's not me. Let me write
> a code sample here:
>
> sub incrind (@ary, $ind) {
> @ary[$ind]++
> }
>
> Are you suggesting that by adding in "@ary ^= 0", like so:
>
> sub incrind (@ary, $ind) {
> @ary ^= 0;
> @ary[$ind]++;
> }
>
> that @ary[$ind] does not become NaN, even if $ind>@ary.length? If this
> is what you're suggesting, I cannot see why it would be the case.
> You'll have to enlighten me.
I would expect this, yes. However, your code would be pretty useless,
because it would also the array before setting a single element.
Better code woudl be:
my @a1 ^= 0; # array with default values as 0
my @a2 ^= NaN; # array with default values as NaN
incrind(@a1, 90) # @a1[90] == 1
incrind(@a2, 90) # @a2[90] == NaN
The hyperassignment, ^=, does not have any size to expand
to, so it assues infinite size. In effect, it does
@a1 = map {0} (0..Inf);
> Even with lazy array evaluation, you do LOGICALLY create an array
> with the given length, even if the space only gets sucked up after
> the fact. If @ary^=0 logically creates an infinitely long array, then
> it is a very dangerous operator indeed (but, of course, according to
> a3, it will not).
I would expect it to DWIM, just as Larry said :-). In some contexts,
it will have zero length, in others it will be infinite. I think
there is the potential for great pain while we try to get the
correct behaviour. One of the goals of lazy arrays is for (1..Inf)
to be a reasonably safe concept.
Another quote from a3: "I'm of the opinion that a lazy list is a
definition of the default values of an array, and that the actual
values of the array override any default values"
Dave.