----- Original Message -----
From: Dan Hursh <[EMAIL PROTECTED]>
Date: Friday, July 2, 2004 2:23 pm
Subject: push with lazy lists

> Hi,
> 
> If I can assume:
> 
>       @x = 3..5;
>       say pop @x;    # prints 5
>       
>       @x = 3..5;
>       push @x, 6;
>       say pop @x;    # prints 6
>       say pop @x;    # prints 5
> 
> What should I expect for the following?
> 
>       @x = 3..Inf;
>       say pop @x;    # heat death?
>       
>       @x = 3..Inf;
>       push @x, 6;    # heat death or
>                        # an array with infinity + 1 elements?
>       say pop @x;    # prints 6?
>       say pop @x;    # heat death?

The way I understand the magicness of lazy lists, I'd expect:

@x = 3..Inf;
say pop @x; # prints Inf

@x = 3..Inf;
push @x, 6; # an array with the first part being 
            # lazy, and then the element 6

say pop @x; # prints 6
say pop @x; # prints Inf
say pop @x; # prints Inf
say pop @x; # prints Inf

# etc 

The way I think of a lazy infinite list is kind of like a special object.  It needs to 
keep track of what the start is and what the end is.  Every other element doesn't 
actually exist, but is calculated based on the index of the 
FETCH/STORE/SPLICE/whatever call.

Also, any list that contains and infinite list becomes tied.  The container list's 
FETCH would change so that any accessed index that falls within the indexes "owned" by 
the infinite list would be dispatched to the infinite list.  So, with a list like:

@array = ('a','b','c',2..Inf,"woops");

Elements 0, 1, and 2 would be accessable as normal, but then elements 3 through Inf 
would be dispatched to the infinite list.  However, since "woops"'s index is also Inf, 
and that index is "owned" by the infinite list, it would be impossible to access it 
except through a pop call (which doesn't look at indexes at all).

Actually, I think that this logic could apply to any array/list constructed with .. or 
..., and an infinite list would just be a special case of that.  It would definitely 
be useful in cases like: @array = 1..2000000000;

- Joe

Reply via email to