I am new to python. I have a few questions coming from an armature!

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Wed Aug 17 07:24:05 EDT 2016


BartC writes:

> On 17/08/2016 07:39, Steven D'Aprano wrote:
>> 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

[- -]

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

The original was (c1 -> e1, c2 -> e2, ..., cn -> en) in John McCarthy's
1960 paper on symbolic expressions, with an actual arrow glyph in place
of hyphen-greater-than.

http://www-formal.stanford.edu/jmc/recursive/node2.html (the paper
famously titled "Part I" without any Part II, unless I mistake much.)

It got implemented as (cond (c1 e1) (c2 e2) ... (cn en)), and I'm not
sure when (if c e1 e2) became available as an alternative conditional
expression in the Lisp family (called LISP back then, just like Python
was called PYTHON if it was called at all).

I think Algol 60 had something like "if c then e1 else e2" as an
expression, also due to McCarthy. Keywords probably bold-faced.

I'm perfectly happy with Python's conditional expression syntax, which
cascades surprisingly well. I'm unhappy with C's, not sure why. I think
I would like McCarthy's original syntax.

(Dijkstra had a similar syntax but the clauses were not ordered. Each
guard had to stand alone and any one branch with a true guard could be
chosen. But that may have been a statement only.)



More information about the Python-list mailing list