For review: PEP 308 - If-then-else expression
Erik Max Francis
max at alcyone.com
Sun Feb 9 15:53:23 EST 2003
Piet van Oostrum wrote:
> It just dawned on me that the 'if' is not really necessary.
> "->" would be a more pythonic operator than "?" I think, because it
> stands
> out more. And indeed it looks a bit strange to have the other part as
> a
> keyword.
I agree that if you're not going to have the original ?: form, then
using ? and a keyword is not going to be pretty.
> What about:
> condition -> (true part, false part)
> The (,) is not a tuple here but it belongs to the -> and the -> says
> to
> select one of the expressions based on the condition and evaluate
> that;
> kind of lazy indexing.
I don't know, it's not really blowing my skirt up. It lacks a certain
transparency to it; I mean, if I'm new to the language and I see
safeSqrtX = if x > 0.0 then math.sqrt(x) else 0.0
[setting aside for the time being the issue of the adding of the keyword
`then'] then I have a pretty good chance of understand what that's
supposed to mean.
I must say that I don't find p -> (x, y) too offensive, so that's an
awfully good start.
> We could then also have one for ints rather than bools:
>
> i -> [ v_0, v_1, v_2, ... ]
> which would pick v_i and evaluate that.
> Also here the [ ] is not really a list notation but belongs to the ->.
I don't know if this makes sense; if i counts from 0, then
condition -> (x, y)
would be
bool(condition) -> [y, x]
right? That would seem to lead to confusion to me.
For the record, I have no problem with introducing a form that extends
to multiway choices, and just has the conditional operator as a
degenerate case.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Life is an effort that deserves a better cause.
\__/ Karl Kraus
Alcyone Systems / http://www.alcyone.com/
Alcyone Systems, San Jose, California.
More information about the Python-list
mailing list