Vote on PEP 308: Ternary Operator

Beni Cherniavsky cben at techunix.technion.ac.il
Mon Mar 3 03:49:38 EST 2003


On 2003-03-02, Anders Hammarquist wrote:

> Hmm, there was the Q option (fill-in). So if nothing else, you can always
> come up with 3 randomly horrendous syntaxes, and then reject those three.
> Of course, you also have to just how horrendous you syntax is...
>
Hey, that's easy <wink>:

$$
x_\lambda =
\begin{cases}
x & \text{if $\lambda$ is an eigenvalue;}\\
-x & \text{if $-\lambda$ is an eigenvalue;}\\
0 & \text{otherwise.}
\end{cases}
$$

http://www.math.harvard.edu/texman/node26.html#SECTION00089000000000000000

As long as you keep the TeX flavour, it's still unacceptably
unpythonic.  E.g.:

x[l] = cases { x if eigenvalue(l),
               -x if eigenvalue(-1),
               0 otherwise }

Oops, wait, that's not that bad :-).  The ``cases`` keyword can be
omitted and the braces should perhaps become parentheses...

To make it horrendously unaceptable (but readable, after all I'm
mimicing math notation), let's do ascii art <;->:

x[l] = / x  if eigenvalue(l),
       |  -x if eigenvalue(-1),
       \ 0  otherwise

(there is variable number of ``|`` lines; you can't go lower than two
options, since then the construct is redudant).

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>

True elegance has negative overhead so it isn't subject to tradeoffs.






More information about the Python-list mailing list