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

lazy context

Thread Next
Yuval Kogman
May 20, 2005 11:48
lazy context
Message ID:

Some of us on #perl6 bitched once more about how lazy will make our
IO brain hurt a lot.

The concensus is that a lazy context has not been discussed yet.

Here is a proposal for lazyness defined with coroutines.

we have a lazy modifier:

	my $a = lazy { get_value(5, 10) };
	my @array = lazy gather { ... take ... };

What it returns is a proxy object that vivifies to a true value, or
in the case of list context lazy, a proxy object array that
implements a generator.

The rvalue of the lazy context modifier is turned into a coro
closure, and is invoked only when the value is accessed.

Moreover, in lazy context, if the coro yields instead of finishing,
then it is not finalized into a real value. Here's how the range
operator would be implemented:

	sub &infix:<..> ($from, $to where { $to < $from }){ reverse $to .. $from }
	sub &infix:<..> ($from, $to) { lazy gather {
		while ($from <= $to) {

In this case, take in lazy context gather would yield.

The only "builtin" feature that needs to be added is that coroutines
can masquerade as their return value, and not a code reference, but
AFAIK proxy objects will give us that anyway, right?

 ()  Yuval Kogman <> 0xEBD27418  perl hacker &

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