a = b = 1 just syntactic sugar?

Michael Chermside mcherm at mcherm.com
Mon Jun 9 14:44:14 CEST 2003


Ed Avis writes:
> Oh.  I thought someone said on this newsgroup only a few days ago that
> they did not, when I mentioned that
> 
>     cond and x or y
> 
> is a well-known substitute for a conditional operator like C's
> (cond ? x : y) or Haskell's (if cond then x else y).  Someone said
> that it wouldn't work, because x and y would be evaluated in either
> case.
> 
> But you're right, they do short-circuit, and so there is no need for a
> separate conditional operator (provided you consider the and-or trick
> a readable idiom).

It looks like you somehow managed to overlook the most vigorous
discussion ever to grace this newsgroup. (OK, maybe not the most
vigorous, but I can't recall another that generated more posts.)
Here's the clifs notes:

 (1) Python doesn't have a conditional expression.
 (2) Python has workarounds, notably "cond and x or y".
 (3) The workarounds don't really satisfy proponents, for 
     various reasons (don't short circuit, don't work in some 
     cases, or too unreadable for sane use).
 (4) Guido decided to throw it to a vote, and said he'd abide
     by the result. Then he simply shut up about it.
 (5) A weeks-long firestorm raged on this newsgroup as people
     proposed somewhat less than 100 syntax alternatives and
     wrote reams of missives on the subject. Eventually a vote
     was held (and at least one extra vote just be sure things
     were overdone).
 (6) There was discussion after the vote was announced about
     how to interpret the results.
 (7) Guido hasn't said a word about it ever since. Probably
     because he's been working on things like releasing 2.3
     which seem more important than a syntax change in some
     future version.

If you want to bring the subject up, please feel free to do
so after going through the archives and reading all postings
with a subject line including the text "PEP 308". As far
as I'm concerned, anyone who can claim to have read ALL such
posts is well-enough informed to be bringing up the subject
again. Otherwise, go read up on it, or wait for Guido to find
time to do the same. (Sorry, Ed, I'm not trying to jump all 
over YOU, just to prevent the discussion from starting fresh 
before we get some sort of finality to the previous discussion.)

-- Michael Chermside






More information about the Python-list mailing list