A possible lazy evaluation system?

Stephen Horne intentionally at blank.co.uk
Tue Mar 11 10:12:45 EST 2003


On Tue, 11 Mar 2003 08:08:44 -0600, Skip Montanaro <skip at pobox.com>
wrote:

>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?

I had in mind an idea where the call notation would create a kind of
call-context object. The functions bytecode would look at the call
context to determine what the parameters should be.

The call context would contain references to the callers scope and
pointers to the parameters expression bytecode stuff. This should be
enough to either create a lambda or evaluate immediately.

The reference to scope (rather than immediate creation of a closure)
should be possible, though I have a nasty feeling that each parameter
would need to supply three items in the context...

1.  Closure-aware bytecode compiled expression (for embedding in
    lambda)

2.  Non-closure bytecode compiled expression expecting callers scope
    to be in effect, for non-lambda parameters.

3.  Compiled bytecode to perform closure construction when lambda is
    needed.

Of course, that is annoyingly complex and probably horribly
inefficient :-(





More information about the Python-list mailing list