David Green writes:
> Then I thought that maybe "for" doesn't need to work lazily (except that 
> the conveniently just-posted Synopsis 4 confirms that it is supposed to 
> be lazy).  Or maybe "for" is only "as lazy as is reasonable", meaning if 
> it knows how (e.g. if you're using an array or filehandle, which have 
> known ways to meander through lazily), or if you write a really fancy 
> iterator for your object that can handle laziness.  

The implementation of C<for> will be very simple.  Something like:

    sub for ([EMAIL PROTECTED], *&code) {
        code(*splice @args: 0, &code.arity) while @args;
    }

So all the laziness goes into the array implementation.  But you don't
even need to write your iterator fancily.  If you just write your scalar
version of postcircumfix:<>, Perl will do the rest.  The list version
isn't all that complicated either.  Something like:

    method postcircumfix:<> ($self: *%opt) returns List { 
        scalar $self.<*%opt>, $self.<*%opt>  # [1]
    }

If I write it functionally like that, Perl will still do all the rest.
Laziness is built right in the language.  And that's one of the biggest
semantic differences from Perl 5.

Luke

[1] Look, Larry, I had to use C<scalar>!  Maybe we _do_ need to revive
$()!

Reply via email to