[Python-ideas] And now for something completely different

Joel Bender jjb5 at cornell.edu
Fri Sep 19 21:46:23 CEST 2008

Cliff Wells wrote:

> So... now, here's my shiny new idea: lazy evaluation of function
> arguments (by some explicit syntactical indicator).  Arguments would not
> be evaluated until they are encountered *at runtime* in the function
> body.  They could be compiled, but not evaluated.

This is called "pass by name":


Syntactically you need some parameter annotation that says you want 
pass-by-name semantics, then add a "thunk" layer when those parameters 
are used in the code.

Note that in languages that support pass-by-name, I happen to be 
familiar with ALGOL, it operates on both the left and right hand side of 
assignment statements.  Perhaps something like this:

     >>> def foo(arg : __byname__):
     ...     print arg
     ...     arg = (arg * 3) + 1
     ...     print arg
     >>> x = 2
     >>> foo(x)
     >>> print x

> I think this would have appeal outside of my particular desire (lazy
> evaluation is a useful feature in-and-of itself) but would also solve my
> particular issue (I could implement functional versions of any control
> structure I like, and even implement new ones).

I'm with you, I think there are quite effective uses for this 
functionality, but nothing that will combat the wave of "why this is 
fundamentally wrong" or "there's a better way to do it" arguments.


More information about the Python-ideas mailing list