ternary operator

Alex Martelli aleax at aleax.it
Fri Feb 7 01:00:09 CET 2003

John Roth wrote:
>> value = (lambda: valTrue, lambda: valFalse)[not selector]()
> Of course you can do it that way. Now try explaining that syntax
> to your average COBOL programmer attempting to learn a more
> modern language.

Why would a Cobol programmer be looking for a "ternary" he's
never seen in Cobol?!  Ternary is for C'ers, Perl'ers, etc.  Cobolers
will be quite happy with:

if selector: value = valFalse
else: value = valTrue

Trust me -- I know several excellent Cobol experts and ternary
is NOT what they're looking for.  "PICTURE" and other uses of
fixed-point are much more likely to be it, or maybe (though that
still baffles me a bit) "ADD a TO b GIVING c" as an alternative
to "weird, algebraic" (sic) "c = a + b" ...


More information about the Python-list mailing list