[Python-ideas] And now for something completely different

Scott Dial scott+python-ideas at scottdial.com
Thu Sep 18 05:05:12 CEST 2008

Josiah Carlson wrote:
> I don't know of a spelling of deferred execution blocks that I would
> find reasonable :/ .

His request is worse than that. He didn't ask for deferred execution, he
asked for deferred values. In python Right Now, you can already do
deferred execution blocks (forgetting the "I don't like seeing lambdas!"
argument). Rather, he wants to be able to have arbitrary expressions be
treated as lazy, not at the call-site either but determined by the receiver:

I'd prefer to write

def foo ( lambda: arg ):
    return arg # evaluation happens here
foo ( x )

I'm sorry but this will never, ever, ever happen in Python. That is such
a *huge* shift in semantics that you should go use a different language.
In such languages, it is *impossible* to know when the expression will
actually be evaluated, and while this is fine in a purely functional
environment, this is not easy to deal with in imperative programming.

If you write "foo(bar())", then you have no way of knowing whether
"bar()" is ever run. And in a world that depends on side-effects, that
forces you to force evaluations of expressions. You would be forced to
write "x = bar(); foo(x)" (assuming assignment isn't lazy), which is
less clear than having to write "foo(lambda: bar())" in the opposite
case. Explicit is better than implicit.


Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu

More information about the Python-ideas mailing list