Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: (test) ? a:b Date: Thu, 23 Oct 2014 16:44:06 +0300 Organization: A noiseless patient Spider Lines: 27 Message-ID: <878uk6x5nd.fsf@elektro.pacujo.net> References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> <7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="32006"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N4UerdpOKQ5OHCRnMUf76" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:N3XcFgp/kKlEzWejbqCYHKD8XJU= sha1:/yvuiw2UbLtAq1jE0aNbASMwXOA= Xref: csiph.com comp.lang.python:79515 "BartC" : >> 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