develooper Front page | perl.perl6.language | Postings from July 2005

lazy list syntax?

Thread Next
Flavio S. Glock
July 27, 2005 16:17
lazy list syntax?
Message ID:
How can I create a lazy list from an object?

I have an object representing the sequence "1..Inf".
I tried creating a Coroutine, and then assigning the Coroutine to an
Array, but it only yielded "1":

  my @a = $span.lazy;   # "1"

The coroutine worked fine in a "while" loop, but it didn't work in a "for" loop.

This is the implementation (in "ext/Span"):

coro lazy ($self: ) {
    my $iter = $self.iterator();
    loop { 
        my $n = $;
        return unless defined $n;
        yield $n;

I understand that this is not fully specified yet, but I'd like to
start writing some tests for it.

- Flavio S. Glock

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About