[Noisebridge-discuss] PyClass 2011-04-18
Seth David Schoen
schoen at loyalty.org
Mon Apr 18 05:40:27 UTC 2011
Timmy Shih Jun Yee writes:
> * Short-circuit evaluation (i.e. Lazy evaluation)
I don't agree that short-circuit and lazy evaluation are the same thing.
https://secure.wikimedia.org/wikipedia/en/wiki/Short-circuit_evaluation
https://secure.wikimedia.org/wikipedia/en/wiki/Lazy_evaluation
Short-circuit evaluation is what causes
def cat():
print "meow"
return True
def dog():
print "woof"
return True
some_animal = cat() or dog()
to print only "meow" and not also "woof" (because the interpreter
knows that the expression will be true without needing to look at
the return value of dog()).
Lazy evaluation is what allows something like
from itertools import takewhile, ifilter, count
def even(x):
return x % 2 == 0
def less_than_ten(x):
return x < 10
print list(takewhile(less_than_ten, ifilter(even, count())))
to work, because it doesn't get any more values out of count() than
are necessary for the caller's purposes, even though count() is capable
of providing an unlimited number of values.
--
Seth David Schoen <schoen at loyalty.org> | Qué empresa fácil no pensar en
http://www.loyalty.org/~schoen/ | un tigre, reflexioné.
http://vitanuova.loyalty.org/ | -- Borges, El Zahir
More information about the Noisebridge-discuss
mailing list