On 17/08/2016 07:39, Steven D'Aprano wrote:
On Wednesday 17 August 2016 06:59, Lawrence D’Oliveiro wrote:

[Quote]
        trueval if cond else falseval

"Go to the movies, if I finish work on time, otherwise just go home."

Is there /any/ programming language that uses a similar form?

Apart from Python, except that it only uses it for expressions, while the English uses statements.

Every time you read the C syntax, you lose another three minutes off your
lifespan. That's how ugly it is.

Rather than ask why Python uses `trueval if cond else falseval`, you should ask
why C uses `cond ? trueval : falseval`. Is that documented anywhere?

I'm not fond of C's a ? b : c but the principle is sound. I generally use it as:

   (a | b | c)               # /with/ the parentheses

which is a direct equivalent of:

  if a then b else c fi      # from algol 68

So it matches if-statements. And follows the same pattern as:

   (n | a, b, c ... | z)

That is, you are given an index, or condition, and based on that you can skip to the option you want and ignore the rest. You don't start with the alternative that you may then have to discard.

Anyway a?b:c was existing practice. At least the order of a,b,c could have been retained if not the exact syntax.

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to