advice needed for lazy evaluation mechanism
dieter at handshake.de
Thu Nov 12 08:53:57 CET 2009
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes on 10 Nov 2009 19:11:07 GMT:
> > So I am trying to restructure it using lazy evaluation.
> Oh great, avoiding confusion with something even more confusing.
Lazy evaluation may be confusing if it is misused.
But, it may be very clear and powerful if used appropriately.
Lazy evaluation essentially means:
you describe beforehand how a computation should be
performed but do this computation only when its result is immediately
Of course, this makes it more difficult to predict when the computation
actually happens -- something potentially very confusing when the computation
has side effects. If the computation is side effect free, potentially
great gains can be achieved without loss of clarity.
Python supports lazy evaluation e.g. by its genenerators (and
generator expressions). Its "itertools" module provides examples
to efficiently use iterators (and by inclusion generators) without
More information about the Python-list