----- Original Message ----- From: Dan Hursh <[EMAIL PROTECTED]> Date: Friday, July 2, 2004 10:32 pm Subject: Re: push with lazy lists
>> Joseph Ryan wrote: > I guess that's true with X..Y lazy lists. I thought there were > other > ways to make lazy lists, like giving it a closure that gets called > lazily to populate the list with the result's being cached. I > can't > remember the syntax though. I think gather was one way. Maybe > I'm just > remembering wrong. > > Anyhow, I was thiking that was how X..Inf was implemented. That > would > be foolish in this case. > > how 'bout > > @x = gather{ > loop{ > take time > } > } # can this be @x = gather { take time loop } > push @x, "later"; > say pop @x; # "later" > say pop @x; # heat death? > say @x[rand]; # how about now? I'm a bit confused by your syntax, but I think I understand what you mean. I was under the impression that loops were not lazily evaluated, but essentially run until they were broken out of. The advantage of using an infinite list is just that you have an iterator that never runs out. > > 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). > > I was wondering about lazy list where we don't know how many > element it > might generate. Admittedly, I picked a poor example. I would > right to > assume woops would also be accessable with @array[-1], right? Oh yeah, that would work too. :) - Joe