[Python-3000] Wild idea: Deferred Evaluation & Implicit Lambda

John Williams shponglespore at gmail.com
Wed May 31 17:31:33 CEST 2006


On 5/30/06, Josiah Carlson <jcarlson at uci.edu> wrote:
> I'm still not convinced that
> 'lazy <expression>' or your equivalent promise class are necessary or
> desireable for the evolution of Python; especially given the simplicity
> of the lambda solution.

I may be just seeing that I want to see, but by my reading of Talin's
original posting, it looks like 'lazy <expression>' was not part of
what he was actually proposing. The actual proposal was to declare
parameters 'lazy' in the function definition, with the effect of
creating an implicit lambda at each call site.

I don't think this feature is a good fit for Python, but it a has a
lot of history so I don't want to see it go down without getting its
due.

I believe the first language to have a similar feature was Algol,
where all arguments were passed "by name". The general consensus seems
to have been that this was a very bad idea, since the only modern
languages that work this way are pure functional languages (Haskell,
Clean, etc.)

The ability to introduce more fine-grained laziness, as proposed here,
seems to be more common in non-pure functional languages (that is,
functional languages that allow side-effects)--I've seen two proposals
from highly-regarded functional language researchers to add similar
constructs to ML.

Laziness is probably most common in functional languages because in
many ways it's an alternative to side-effects. On one hand,
eliminating or discouraging side-effects in a language make laziness
much more attractive because it's possible to re-order the evaluation
of purely functional code without changing its meaning. On the other
hand, laziness has much more value in a functional setting because
many purely-functional algorithms have worse asymptotic complexity
than their procedural counterparts unless laziness is allowed.

That said, I have seen lazy arguments in one OO language, namely
Scala. It's a fairly new language with a lot of novel features, so
it's a bit early to single out a feature and say it's (?:good|bad)
because Scala is a (?:spectacular success|miserable failure), but it
doesn't seem to have caused an inordinate amount of confusion, and
there's an awful lot of cool stuff you can do with deferred arguments,
such as implementing boolean operators, looping constructs,
"with"-like constructs, etc.

The fact that you can get the same effect with explicit lambdas
doesn't detract from the value of lazy arguments IMHO because a lot of
the time the extra syntactic weight is just too much to
tolerate--imagine if the 'and' and 'or' operators required a callable
as their second argument!

The thing that really makes this feature unattractive in Python is
that it would become impossible to tell when or if a function will
evaluate its arguments without seeing the function's definition. Even
this might be OK if not for inheritance, but the possibility of
overriding a normal method with a lazy method just makes my skin
crawl!

--jw


More information about the Python-3000 mailing list