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

Sean Ross sross at connectmail.carleton.ca
Sun Feb 9 20:31:07 EST 2003


"Alex Martelli" <aleax at aleax.it> wrote in message
news:R3B1a.158635$0v.4436343 at news1.tin.it...
>
> So maybe the syntax should be:
>
>     [whentrue if condition else whenfalse]
>
> i.e., just like in the PEP *BUT* with brackets around it.  Minus: the
> brackets suggest "list" and there's no list here.  Pluses: remove the
> "can almost appear anywhere", add the "tell the reader", exploit the
> "trailing if" habit from LC's -- the lack of any 'for' clause should be
> sufficient to distinguish this from LC's, I think.
>
>
> Alex
>

I like this syntax. I agree with the minus point, although there "sort of"
is an implicit list, the list [whentrue, whenfalse]
which you are "sort of" filtering based on 'condition', although the
filtering does not return a list, rather an evaluated expression. I do think
it can be confused with list comprehensions. But, without the 'for' , and
with the inclusion of 'else', they do have a somewhat different appearance.
Mostly its the square brackets. I like them. I think parentheses would not
distinguish this construct strongly enough. Square brackets, I think, will.
I don't care for curly braces in general, so I'd prefer not to see those.
Pipes perhaps?
    |whentrue if condition else whenfalse|
Doesn't really stand out...

Anyway...yeah, I like it...
Sean






More information about the Python-list mailing list