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

holger krekel pyth at devel.trillke.net
Sat Feb 8 21:15:32 EST 2003


Paul Rubin wrote:
> "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")
> 

While i find David's comment quite appropriate and funny 
(don't feel offended, please) i must say that your suggestion
is not too bad.  It simply means a second way to spell 'lambda' 
but enables your above use. 
 
> 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.

But increasing usage of punctuation indeed is dubious (in python). 

I wonder if c.l.py ever returns to not drown itself in
syntax discussions :-)

    holger





More information about the Python-list mailing list