Joe Gottman wrote:

Alternatively, there might be a new parameter type that indicates that the
parameter is not evaluated immediately:

sub infix:!! ($lsh, $rhs is deferred) {...}

A nice concept! So nice, in fact, that it would be a shame to limit it to function args. I could see myself writing:



my $a is lazy := expensive_fn1(...); my $b is lazy := expensive_fn2(...);

print rand ?? $a :: $b;

I'm not sure quite how the syntax would work (should I be binding or assigning?); but there are definitely cases where this ability is useful. Given this capability, defered evaluation of function args would be trivial.

Another, very different, situation where laziness is good is to abstract fork/join situations:


my $a is lazy_thread := expensive_fn1(...); my $b is lazy_thread := expensive_fn2(...);

print $a + $b;

In this scenario, each expensive evaluation would be launched as a separate thread. When the resulting value is later used, then the thread would be joined, blocking if the thread is not complete.



Reply via email to