A possible lazy evaluation system?

John Roth johnroth at ameritech.net
Tue Mar 11 16:22:06 EST 2003


"Skip Montanaro" <skip at pobox.com> wrote in message
news:mailman.1047391758.29594.python-list at python.org...
>
>     Stephen> You could then write something like...
>
>     Stephen>   def IF (c, lambda x, lambda y) :
>     Stephen>     if c :
>     Stephen>       return x ()
>     Stephen>     else :
>     Stephen>       return y ()
>
>     Stephen> ...and call it with...
>
>     Stephen>   IF (y != 0, x/y, 1000000)
>
>     Stephen> The 'lambda' asserts that the parameters expression gets
>     Stephen> converted to a parameterless lambda instead of being
evaluated
>     Stephen> immediately.
>
> From a technical standpoint, I think the main problem is the
complication to
> the bytecode compiler.  Note that when compiling a function call, it
would
> have to have the function prototype available to it.

That's not really the case. I put together a protoPEP at one time that
used a special syntax (braces instead of parenthesis) to indicate that
a call was intended to have lazy evaluation semantics, and also to
independently indicate that the function/method was prepared to handle
lazy evaluation semantics.

It actually works out nicely, since it's real obvious what to do with
all four
cases at run time, and it does not impact the standard case at all.

I never sent it in because I didn't like the syntax. Maybe it's time to
get it off the HD and submit it.

John Roth







More information about the Python-list mailing list