Proposal: function which simulates C ?: operator

Peter Hansen peter at engcorp.com
Mon Jul 12 09:14:09 EDT 2004


Reinhold Birkenfeld wrote:

> Peter Hansen wrote:
>>It won't happen because (a) it's a trivial function to write
>>on-demand,
> 
> How do you write this function without lambda in the call?

Basically, you use if/then like you are "supposed" to. :-)
But the OP wasn't asking about a short-circuit version, just
the trivial fully evaluated function approach.

>>and (b) there are already several different ways of
>>spelling it with current Python syntax if you don't want a
>>function
> 
> One uglier than the other.

Agreed.  Use if/then and save the sanity of your maintenance
programmers.

>>and (c) I suspect that the requirement for short-circuit
>>evaluation would actually be *more* common in Python than it
>>appears it is in C++ based on your very limited sample population.
> 
> ACK.

Ironic that Bill the Cat changed the meaning of that from
positive to negative. :-)  (Or did he always use mixed-case,
so that all-caps ACK is still uniquely ASCII?)

-Peter



More information about the Python-list mailing list