Request for comments: use-cases for delayed evaluation

dieter dieter at handshake.de
Fri May 18 02:12:50 EDT 2018


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> Suppose Python had a mechanism to delay the evaluation of expressions 
> until needed. What would you use it for?

Delayed evaluation is some form of "lazy evaluation": evaluate an
expression (only) at the time, it is needed (maybe for the first time).

The avocates of "lazy evaluation" bring forward that it gives you
a convenient new modularization facility: you can separate the description
for the construction of (potentially huge or even infinite) data structures
from the algorithms operating on those structures. The "lazy evaluation"
ensures that the structure is "unfolded" only so far as a concrete
algorithm requires it.

An example could be a game. Lazy evaluation would allow to describe
once and for all how to compute the tree of game states reachable from
a given game state (usually a huge, maybe even an infinite tree).
Various algorithms for the selection of the next game move could
all work on tree (and would be some form of tree search).

With lazy evaluation, Python might become more attractive in
areas where conceptually huge data structures can be involved: games,
articial intelligence, proving systems, ...




More information about the Python-list mailing list