[Python-Dev] Adding C ternary select (a?b:c) to Python?
Ka-Ping Yee
ping@lfw.org
Mon, 31 Jan 2000 21:56:28 -0600 (EST)
On Mon, 31 Jan 2000, Tim Peters wrote:
> If I didn't know better <wink>, I'd say there's an actual consensus here:
> it seems we would all agree to "(if cond then true else false)" spelling.
Actually, i'm afraid i don't. I initially chose the "then/else"
spelling specifically because "if" flags the eye to the beginning
of a statement. My line of thinking was, "'then' for expressions,
'if' for statements."
> I had already channeled that for the group's benefit <wink>. For 1.6,
> without absurd overloading of some other keyword (like "if cond def true
> ..."), that seems to leave
>
> (if cond: true else false)
Sorry, i like that even less. It seems to abuse the colon, for the
colon (to me) signals both (a) This Is A Statement and (b) This Begins
A Block, neither of which are true here.
> How much is that hated? I hate it myself, not least because I'd have to
> change IDLE's parser to guarantee it couldn't get confused by the colon
> here:
>
> big = (
> if x >= y:
> x else y)
I consider this a symptom of the colon-abuse i just described...
> BTW, I'm not entirely convinced "then" would have to be a keyword to make
> "if x then y else z" work: couldn't the grammar use WORD and verify it's
> specifically "then" later?
Quite possibly, yes -- though i figured it wouldn't be *too*
large an issue to make "then" a keyword, since i can't imagine
anyone naming a symbol "then" except under the most freakish
of circumstances. A quick check shows no symbol by that name
in any of the Python scripts or modules we have here.
-- ?!ng