[Python-Dev] Re: ternary operators (fwd)
Tim Peters
tim_one@email.msn.com
Tue, 1 Feb 2000 02:45:42 -0500
[Moshe Zadka]
> ...
> Adding nothing to the discussion, let me just mention how Scheme (my
> second favourite language) does it:
>
> (if bool true-result else-result)
>
> Well, of course this isn't relevant to Python because statements are not
> expressions, but there might be something in it: if could be also used
> as a function taking three arguments:
"if" is a special form in Scheme; all Python functions are strict;
short-circuiting is essential here.
> print if(long_answer, "Very good!", "correct")
>
> I have no idea how this will play with the parser. Anyone?
if(a, b, c)
can't be distiguished from
if (a, b, c):
before the colon is seen, so it requires more lookahead than Python's parser
is comfortable doing.