A possible lazy evaluation system?
Skip Montanaro
skip at pobox.com
Tue Mar 11 09:08:44 EST 2003
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. More insidious:
class Foo:
def IF(self, c, lambda x, lambda y):
...
...
and somewhere else:
foo = Foo()
and further down, maybe way, far away:
murphy(foo)
where murphy is defined as
def murphy(bar):
return bar.IF(y != 0, x/y, 1000000)
How does the compiler know (at compile-time) that bar.IF is going to be
bound at runtime to Foo.IF so it can check the laziness of the parameters
and generate the proper code?
Skip
More information about the Python-list
mailing list