(test) ? a:b
Marko Rauhamaa
marko at pacujo.net
Thu Oct 23 09:44:06 EDT 2014
More information about the Python-list mailing list
Thu Oct 23 09:44:06 EDT 2014
- Previous message (by thread): (test) ? a:b
- Next message (by thread): (test) ? a:b
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"BartC" <bc at freeuk.com>: >> Ah, but what would >> >> x = [f, g][cond]() >> >> produce? > > It will select f or g (which should refer to functions), and call one of > those depending on cond. That's not a problem. > > The problem is it will still evaluate both f and g, That's not really the problem. The problem is in readability. However, the "[f, g][cond]()" technique is how pure lambda calculus implements conditional branching so it is interesting in its own right. IOW, you can do "short-circuiting" in purely functional programming: j = j + 1 if j < 10 else 3 <=> j = (lambda: 3, lambda: j + 1)[j < 10]() Marko
- Previous message (by thread): (test) ? a:b
- Next message (by thread): (test) ? a:b
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list