For review: PEP 308 - If-then-else expression

Paul Paterson hamonlypaulpaterson at houston.rr.com
Sat Feb 8 23:25:08 EST 2003


"Paul Rubin" <phr-n2003b at NOSPAMnightsong.com> wrote in message
news:7x3cmyl22l.fsf at ruckus.brouhaha.com...
> "Paul Paterson" <hamonlypaulpaterson at houston.rr.com> writes:
> > However, for me this is the crux of the matter. Short circuiting pretty
much
> > has to be the justification for implementing this PEP because if you
don't
> > need short-circuiting you can write a trivial three line iff function.
But
> > then if short-circuiting is the main reason then I think I'd rather open
up
> > the general idea of how to implement lazy evaulation in a Pythonic way.
>
> How about further abuse of colon:
>
>    f(:expression)
>
> is short for f(lambda: expression)
>
> So we'd implement a conditional expression with
>
>    def cond(condition, v1, v2):
>       if condition:
>          return v1()
>       else:
>         return v2()
>
> To call it, we'd say, for example,
>
>    print cond(x >= 0, :sqrt(x), :"imaginary roots")
>
>
> I don't see immediately whether this makes any syntax ambiguities with
> existing statements, since I can't think of anyplace where colon can
> currently appear where an expression can also appear.

When I first saw this I thought it was horrible - you can hardly tell that
the ":" is there.

About two hours later I thought, "wait a minute - you don't really need to
see that the ":" is there... its mostly irrelevant except when you are
particularly interested in the delayed evaluation". Lazy evaluation should
be almost invisible because it is a semantic "pass".

I await the next two hours with interest to see if I completely change my
mind again.







More information about the Python-list mailing list