conditionals in lambdas?

Steve Horne sh at ttsoftware.co.uk
Thu Nov 9 12:20:21 EST 2000


On Thu, 09 Nov 2000 15:45:09 +0000, Steve Horne <sh at ttsoftware.co.uk>
wrote:

>This can be adapted as follows...
>
>  ((lambda : no_value, lambda : yes_value) [condition]) ()

I should say this isn't real lazy evaluation, for several reasons...

1.  Because the lambdas don't remember the results after the first
    evaluation, so in some expressions they could be evaluated
    repeatedly. A good implementation of lazy evaluation would try
    hard to avoid this.

2.  Because there is no intelligence in the order of evaluation. A
    good lazy implementation would evaluate the easiest subexpressions
    first in hope of optimising out the more complex subexpressions.

3.  Because the lambdas don't transparently act as values when needed.
    You have to explicitly evaluate them.

Even so, it allows a few lazy-evaluation style tricks.

-- 
Steve Horne
sh at ttsoftware.co.uk



More information about the Python-list mailing list