ternary operator

John Roth johnroth at ameritech.net
Thu Feb 6 16:05:19 EST 2003


"Paul Rubin" <phr-n2003b at NOSPAMnightsong.com> wrote in message
news:7xlm0udvxy.fsf at ruckus.brouhaha.com...
> "John Roth" <johnroth at ameritech.net> writes:
> > > > def cond(selector, valTrue, valFalse):
> > > >    if selector:
> > > >       return valTrue
> > > >    return valFalse
> > >
> > > Righ, that's easy enough, but how many bugs will be cause by
> > > people forgetting that it doesn't short-circuit?
> >
> > Which is exactly the reason I suggested that it might be a good idea
to
> > pursue some way of allowing a function to do lazy evaluation of its
> > operands.
>
> 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.

John Roth






More information about the Python-list mailing list