pep 308: why doing (almost) nothing suffices
Terry Reedy
tjreedy at udel.edu
Sun Mar 9 22:43:08 EST 2003
"Edward K. Ream" <edream at tds.net> wrote in message
news:YWQaa.2838$ES3.2225226 at kent.svc.tds.net...
> Naturally this isn't very good, or pep 308 wouldn't exist. My
"grand
> insight" in the tub was simply that once could define another
version of
> this code:
>
> def choose_eval(cond, a, b): # warning: evals all arguments
>
> if cond: return eval(a)
> else: return eval(b)
How is your quote proposal significantly different in effect from
lambda-izing and then calling the arguments, which can also be done
today (as has already been discussed)?
def choose(cond, a, b):
if cond: return a()
else return b()
choose(y!=0, lambda: x/y, lambda: BIGNUM). Using lambda gets
expression parsed (and syntax-error checked) as compile time.
Terry J. Reedy
More information about the Python-list
mailing list