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

lazy list syntax?

Thread Next
From:
Flavio S. Glock
Date:
July 27, 2005 16:17
Subject:
lazy list syntax?
Message ID:
aa47605d050727161748eb9a9d@mail.gmail.com
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 = $iter.next;
        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.

Thanks!
- Flavio S. Glock

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About