Adding C ternary select (a?b:c) to Python?

Dear developers, Eric Raymond has sent me the following patch, which adds conditional expressions to Python. I'd like to hear opinions on whether this is a good thing to add to Python, and whether this is the right syntax. I am a bit skeptical about whether this is sufficiently Pythonic, but on the other hand there have always been requests for such a feature, and the existing solutions are ugly: a and b or c only works when you know for sure that b will never be false, and (a and [b] or [c])[0] is dead ugly... --Guido van Rossum (home page: http://www.python.org/~guido/) Subject: Ternary select -- here it is. From: "Eric S. Raymond" <esr@thyrsus.com> To: Guido Van Rossum <guido@CNRI.Reston.Va.US> Date: Sat, 29 Jan 2000 17:40:31 -0500 X-Eric-Conspiracy: There is no conspiracy Dang, Guido, this was *fun*! This patch extends the Python interpreter to support the C ternary operator, and documents the extension in the Reference Manual. The implementation is dead simple and robust: it's adapted from the existing code for if statements, and adds or changes less than 70 lines of code all told. Diffs between last version checked in and current workfile(s): --- Grammar/Grammar 2000/01/28 17:10:18 1.1 +++ Grammar/Grammar 2000/01/29 22:14:05 @@ -61,7 +61,8 @@ except_clause: 'except' [test [',' test]] suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -test: and_test ('or' and_test)* | lambdef +test: bool_test ['?' bool_test ':' bool_test] +bool_test: and_test ('or' and_test)* | lambdef and_test: not_test ('and' not_test)* not_test: 'not' not_test | comparison comparison: expr (comp_op expr)* --- Include/token.h 2000/01/28 17:38:55 1.1 +++ Include/token.h 2000/01/29 01:27:00 @@ -74,10 +74,11 @@ #define LEFTSHIFT 34 #define RIGHTSHIFT 35 #define DOUBLESTAR 36 +#define QUERY 37 /* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */ -#define OP 37 -#define ERRORTOKEN 38 -#define N_TOKENS 39 +#define OP 38 +#define ERRORTOKEN 39 +#define N_TOKENS 34 /* Special definitions for cooperation with parser */ --- Modules/parsermodule.c 2000/01/28 18:03:27 1.1 +++ Modules/parsermodule.c 2000/01/29 22:13:45 @@ -945,6 +945,7 @@ #define validate_star(ch) validate_terminal(ch, STAR, "*") #define validate_vbar(ch) validate_terminal(ch, VBAR, "|") #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**") +#define validate_query(ch) validate_terminal(ch, QUERY, "?") #define validate_dot(ch) validate_terminal(ch, DOT, ".") #define validate_name(ch, str) validate_terminal(ch, NAME, str) @@ -963,7 +964,8 @@ VALIDATER(exec_stmt); VALIDATER(compound_stmt); VALIDATER(while); VALIDATER(for); VALIDATER(try); VALIDATER(except_clause); -VALIDATER(test); VALIDATER(and_test); +VALIDATER(test); +VALIDATER(bool_test); VALIDATER(and_test); VALIDATER(not_test); VALIDATER(comparison); VALIDATER(comp_op); VALIDATER(expr); VALIDATER(xor_expr); VALIDATER(and_expr); @@ -1829,12 +1831,34 @@ } /* validate_except_clause() */ +/* bool_test ( | bool_test ? bool_test ) + * + */ static int validate_test(tree) node *tree; { + if (!validate_ntype(tree, test)) + return 0; + else if (NCH(tree) == 1) + return(validate_bool_test(CHILD(tree, 0))); + else if (validate_numnodes(tree, 5, "expr")) + { + return validate_bool_test(CHILD(tree, 0)) + && validate_query(CHILD(tree, 1)) + && validate_bool_test(CHILD(tree, 2)) + && validate_colon(CHILD(tree, 3)) + && validate_bool_test(CHILD(tree, 4)); + } +} /* validate_test() */ + + +static int +validate_bool_test(tree) + node *tree; +{ int nch = NCH(tree); - int res = validate_ntype(tree, test) && is_odd(nch); + int res = validate_ntype(tree, bool_test) && is_odd(nch); if (res && (TYPE(CHILD(tree, 0)) == lambdef)) res = ((nch == 1) @@ -1848,7 +1872,7 @@ } return (res); -} /* validate_test() */ +} /* validate_bool_test() */ static int --- Parser/tokenizer.c 2000/01/28 17:37:48 1.1 +++ Parser/tokenizer.c 2000/01/29 01:27:26 @@ -99,6 +99,7 @@ "LEFTSHIFT", "RIGHTSHIFT", "DOUBLESTAR", + "QUERY", /* This table must match the #defines in token.h! */ "OP", "<ERRORTOKEN>", @@ -384,6 +385,7 @@ case '}': return RBRACE; case '^': return CIRCUMFLEX; case '~': return TILDE; + case '?': return QUERY; default: return OP; } } --- Python/compile.c 2000/01/28 23:17:19 1.1 +++ Python/compile.c 2000/01/29 22:19:29 @@ -1698,11 +1698,11 @@ } static void -com_test(c, n) +com_bool_test(c, n) struct compiling *c; node *n; { - REQ(n, test); /* and_test ('or' and_test)* | lambdef */ + REQ(n, bool_test); /* and_test ('or' and_test)* | lambdef */ if (NCH(n) == 1 && TYPE(CHILD(n, 0)) == lambdef) { PyObject *v; int i; @@ -1738,6 +1738,32 @@ } static void +com_test(c, n) + struct compiling *c; + node *n; +{ + int op; + REQ(n, test); + com_bool_test(c, CHILD(n, 0)); + + /* is there a following ternary operator? */ + /* XXX optimize the compilation when the guard is a constant */ + if (NCH(n) == 5) + { + int anchor1 = 0, anchor2 = 0; + com_addfwref(c, JUMP_IF_FALSE, &anchor2); + com_addbyte(c, POP_TOP); + com_pop(c, 1); + com_node(c, CHILD(n, 2)); + com_addfwref(c, JUMP_FORWARD, &anchor1); + com_backpatch(c, anchor2); + com_addbyte(c, POP_TOP); + com_node(c, CHILD(n, 4)); + com_backpatch(c, anchor1); + } +} + +static void com_list(c, n, toplevel) struct compiling *c; node *n; @@ -2931,6 +2957,9 @@ break; case test: com_test(c, n); + break; + case bool_test: + com_bool_test(c, n); break; case and_test: com_and_test(c, n); --- Doc/ref/ref5.tex 2000/01/29 21:28:13 1.1 +++ Doc/ref/ref5.tex 2000/01/29 22:00:02 @@ -764,7 +764,7 @@ \section{Boolean operations\label{Booleans}} \indexii{Boolean}{operation} -Boolean operations have the lowest priority of all Python operations: +Boolean operations have the lowest priority of all Python binary operations: \begin{verbatim} expression: or_test | lambda_form @@ -832,6 +832,24 @@ def make_incrementor(increment): return lambda x, n=increment: x+n \end{verbatim} + +\section{Select\label{select}} +\index{select} + +The select operator is a ternary operator with lower priority than +boolean operations (and thus lower priority than all other binary and +unary operators). + +\begin{verbatim} +select_expr: xor_expr | xor_expr "?" xor_expr ":" xor_expr +\end{verbatim} + +If its first operand is nonempty, the value of a select operation is +its second operand; otherwise the value is the third operand. + +(The semantics and precedence level of select are intended to be +unsurprising to programmers familiar with \C's ternary select +operator.) \section{Expression lists\label{exprlists}} \indexii{expression}{list} End of diffs. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> You know why there's a Second Amendment? In case the government fails to follow the first one. -- Rush Limbaugh, in a moment of unaccustomed profundity 17 Aug 1993

Guido van Rossum wrote:
Yee ha! I think that this is a great idea. I'm surprised that using the colon doesn't cause problems. I'm not a grammer lawyer, and don't care that much. I very much would like to see a conditional expression. I wouldn't object if it was spelled differently than C's.
Yup. (a and (b,) or (c,))[0] is even worse. ;) Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.

Jim Fulton <jim@digicool.com>:
I'm surprised that using the colon doesn't cause problems.
Pgen doesn't tag this ambiguous. The LL(1) traversal actually helps here; by the time you see a colon, you already know whether or not you're parsing a ternary telect. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Don't think of it as `gun control', think of it as `victim disarmament'. If we make enough laws, we can all be criminals.

Jim Fulton <jim@digicool.com>:
I'm surprised that using the colon doesn't cause problems.
[ESR]
Interestingly, the very ad-hoc parsing that I described in the compiling/parsing session on devday would be hit by this... I was looking for a colon at nesting level zero. Serves me right for not using a real parse :-) --Guido van Rossum (home page: http://www.python.org/~guido/)

FWIW, the lack of a ternary select is one of the frequently asked questions in my Python courses. It would make TomC happier as well. I'm not sure the latter is a feature. =) On the topic of aesthetics, the C syntax doesn't strike me as the ultimate in pythonicity but it's not too bad either. I can't think of an alternative that doesn't involve a new reserved word. --david

Shouldn't this read #define N_TOKENS 40 ?! Apart from that I wouldn't mind having this patch in the core :-) -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/

[Guido van Rossum]
Marginal; not evil, but of minor utility.
and whether this is the right syntax.
If and only if you were a C programmer first. BTW, insert <wink>s where needed throughout <wink>.
There have always been requests for the union of all features from all other languages.
Too error prone.
Well, I'm the guy who invented that one! The thread that spawned it was just playfully wondering whether it was *possible* -- and if I didn't solve it, Majewski would have using even uglier __xxx__ trickery. I've never used it in a real program, and shoot people who do. So there is no reasonable way to spell ?: as a one-liner today, period. The question is whether that's "a lack" worth doing something about. I can live without it. Surprised that Jim (Fulton) seems so keen on it: his cPickle.c uses ?: exactly once in 4400 lines of C, and in a line that would have been clearer if C had a max function (or is it min? it can take a while to reverse-engineer the intent of a ?:! ... not good when it happens; and I recall one of the contributed patches that went into 1.5.2 longobject.c, that had Guido & I both cracking a C manual just to figure out how C would *parse* a particularly nutso blob of nested ?: thingies). If this goes in (I'm not deadly opposed, just more opposed than in favor), I'd like to see "else" used instead of the colon (cond "?" true "else" false). The question mark is reasonably mnemonic, but a colon makes no sense here. Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>. BTW, a number of other changes would be needed to the Lang Ref manual (e.g., section 2.6 (Delimeters) explicitly says that "?" isn't used in Python today, and that its appeareance outside a string literal or comment is "an unconditional error"; etc). crabby-old-man-ly y'rs - tim

Tim Peters <tim_one@email.msn.com>:
I have to say that I think any ternary syntax that mixes a single-character operator with a keyword would be intolerably ugly.
Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>.
It's not that simple. People clearly want the functionality; we've seen ample evidence of that. Given that, I think the presumption has to be in favor of using the familiar C syntax rather than an invention that would necessarily be more obscure.
I'm certainly willing to fix that. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> [The disarming of citizens] has a double effect, it palsies the hand and brutalizes the mind: a habitual disuse of physical forces totally destroys the moral [force]; and men lose at once the power of protecting themselves, and of discerning the cause of their oppression. -- Joel Barlow, "Advice to the Privileged Orders", 1792-93

I personally haven't been stunned by the ample evidence you mention. While folks do ask about the ternary select periodically in classes and on the net, none of my students at least are especially upset when I point out the readability of: if a: b = c else: b = d
The presumption from the language design point of view is to do what's right regardless of language background, not what's in C -- when Guido remembered that, he chose 'and' and 'or' over '&&' and '||'. When Guido forgot that, he chose integer division =). While all of the folks on this list are comfortable with C, I can point out that a (possibly surprisingly) large proportion of the Python programmers I have taught have never used C or never felt comfortable with it. If CP4E succeeds, that proportion will grow, not shrink. I do think that taking a page from Randy Pausch would be a good idea in this case. My guess is that english words would emerge from trying to teach non-programmers the concept, but I of course don't have data on the topic. I wonder how high-school teachers teach the hook-colon in C intro classes, specifically what _words_ they use. Those words might lead to alternative syntaxes. Finally, something at the edge of my brain is trying to combine the logic of the ternary select (which is clearly related to control flow) and a more generalized switch statement. But I'm not seeing anything syntactically appealing at present. That said, the hook-colon syntax is appealing from a release management perspective because it fits within the current set of reserved words and clearly isn't the hardest concept to teach. --david

The question comes from what "problem" you're trying to solve. The ?: syntax does not introduce any new "functionality" to the language, nor does it make it capable of solving problems or requirements that it can not do at the current time. The second qustion I'd ask is, who is this aimed at? It's certainly not aimed at first-time programmers, as I know from experience that the ?: is one of the hardest things to teach people in C (after pointers), and often I leave it out of training when I did it. It's simply a "shorthand" not a new functionality. If its aimed at experienced programmers, I'd argue that it's at best "non-pythonic" and at worst a hack, taken from a language in which it exposes the "macro assembler" approach. Python is not a language that has been optimized for "minimal typing", it's much more verbose than most languages, and so that argument shouldn' be applied. Perhaps it's for optimization? That was I believe the original argument made for it in K&R, in that optimizers in that day were rather antiquated, wheras today, I believe that any C compiler would get it right if it were expressed in its full form. (Timbot?) So, it comes down to a few questions for me: Does it solve a new problem? No Is it pythonic? No Does it make it faster? No Given Pyton's CP4E goals, and its general place as an easy to use language, I'd argue this patch would be counter to all of those goals. Sorry if I pushed someone's buton, but... I saw a lot of hints at making Python MUCH more complex, which is counter to why I changed and dropped many other languags. Chris -- | Christopher Petrilli | petrilli@amber.org

Christopher Petrilli <petrilli@amber.org>:
Well, in a theoretical sense, you're right. But then, even troff macros and INTERCAL are Turing-complete <my-first-attempt-at-a-Tim-Peters-style-wink>. One of the lessons of Python to this old LISPer is that *notation matters*. Theoretically, Python is a subset of Scheme-with-objects using a vaguely C-like surface notation. But even I would rather write a for-loop than the equivalent recursion. That's why I code in Python now instead of trying to rescue LISP from its desuetitude. So while it is *theoretically* true that ?: adds nothing, it is *practically* true that it enables a large class of idioms that can't otherwise be comfortably expressed. That matters. Now, you can argue that the complexity ?: adds to language is not paid for by the additional convenience; I disagree, but that's at least a defensible argument. But simply saying it "adds nothing to the language" is a red herring -- neither do many of the other base language features. Why, for example, do we have more than one kind of loop construct? Unecessary. Wasteful. Clearly either "for" or "while" must go. As an exercise, try editing your complaint so that it refers to "for" everywhere it now refers to ?:. Contemplate the edited version until you achieve enlightenment ;-). -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> The same applies for other kinds of long-lasting low-level pain. [...] The body's response to being jabbed, pierced, and cut is to produce endorphins. [...] So here's my programme for breaking that cycle of dependency on Windows: get left arm tattooed with dragon motif, buy a crate of Jamaican Hot! Pepper Sauce, get nipples pierced. With any luck that will produce enough endorphins to make Windows completely redundant, and I can then upgrade to Linux and get on with things. -- Pieter Hintjens

[Christopher Petrilli]
Concise expression of common concepts is a Good Thing, though, and there's nothing inherently evil about wanting one of two outcomes <wink>. My impression is that the people historically most in favor of ?: ("or something like it") are also the ones most strongly in favor of embedded assignment ("or something like it"), and I can't *dismiss* either gripe. The Python while 1: x = something_or_other() if not x: break consume(x) idiom is truly grating at first -- more so than the multi-line ?: alternatives, in my eyes.
Indeed, a couple weeks ago we tracked down a "mysterious slowdown" of our core speech recognizer to a particular compiler failing to optimize *unless* we changed a ?: into a long winded if/else! There's really nothing you can say about "any C compiler" -- optimization is much more a black art than anyone in that business will admit to in public <0.9 wink>. C was definitely designed with "by hand" optimization in mind, and, ironically, it's those features (particularly pointer aliasing) that make it harder for compilers to optimize than is, say, Fortran. But regardless of origin, ?: stands or falls on its other merits now. Python's own implementation uses it often enough, and to good effect. So it can't be that Guido hates the idea <wink>. It's just hard to love the syntax.
Would a nice syntax allow clearer expression of some common computations? Probably yes. That's the same basis on which, e.g., list.pop and list.extend and dict.get and 3-argument getattr and ... were adopted. "Faster" applied to those too, but nobody pushed for 'em on that basis. Clearer! That's what really matters. It's the same argument for list comprehensions too.
A good antitode to feature panic is reviewing Misc/HISTORY: Guido's willingness to entertain suggestions far exceeds his willingness to adopt them <wink>. it-would-be-different-if-features-were-just-as-easy-to- take-out-ly y'rs - tim

Christopher Petrilli wrote:
The question comes from what "problem" you're trying to solve.
It would allow you to incorporate logic into expressions. There are contexts where only expressions are allowed, such as: - lambdas - DTML expr attributes in which I'd very much like to incorporate tests.
The ?: syntax does not introduce any new "functionality" to the language,
Yes it does.
Ditto.
Hm. I can't agree. Smalltalk, came out of an essentially CP4E effort two decades ago at Xerox PARC. Smalltalk *only* had conditional expressions. The message: [condition] ifTrue: [do something ...] ifFalse: [do something else ...] is an expression in Smalltalk.
No, it allows testing in expressions.
I don't agree.
Python is not a language that has been optimized for "minimal typing",
That's not the issue.
Yes.
Is it pythonic? No
Pythonicity is relative.
Does it make it faster? No
Who cares? Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.

Don't know much about DTML, but believe that being able to put conditionals in lambdas would make the latter much more useful.
Is anything possible with ?: that's impossible without? No --- Python is Turing-equivalent before and after the change. Is anything easier with ?: --- yes. Does this make up for the added complexity? Dunno (see below).
Strongly agree with the first author --- IME, ?: is very hard to teach. Greg

On Mon, 31 Jan 2000 gvwilson@nevex.com wrote:
Giving Guido one less reason to dislike ?: <wink> Seriously, I disagree with the basic premise of you and Jim: you can *already* have control structures inside experessions with and/or, so even for Jim's twisted meanings for "add new functionality to the language" it's not true.
Is anything easier with ?: --- yes.
For the reader, for the writer or for the cp4e-newbie learning Python? cluttering-another-mailing-list-ly y'rs, Z. -- Moshe Zadka <mzadka@geocities.com>. INTERNET: Learn what you know. Share what you don't.

Moshe Zadka <moshez@math.huji.ac.il>:
You laugh, but this was in fact in my mind. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Nearly all men can stand adversity, but if you want to test a man's character, give him power. -- Abraham Lincoln

Have you ever tried to teach this to relatively experienced programmers (never mind novices) whose background is Fortran, Modula-2, Ada, or anything other than C/C++/Java? It's *really* hard to get the idea across. I tried it in the first Python course I taught at LANL, and wound up spending 15 minutes trying to unconfuse people (and failed). Afterward, one guy said that it made even less sense than using integer offsets to fake linked lists in Fortran-77... Greg

On Mon, 31 Jan 2000 gvwilson@nevex.com wrote:
<but it's hard to get the idea across> You're most certainly right. This, however, refers to usability, not functionality. It makes existing functionality usable by non-timbots. A worthy goal, but it's not the same as adding new functionality. -- Moshe Zadka <mzadka@geocities.com>. INTERNET: Learn what you know. Share what you don't.

[Tim, tosses off cond "?" true "else" false in apparent hatred of colons] [Eric S. Raymond]
I have to say that I think any ternary syntax that mixes a single-character operator with a keyword would be intolerably ugly.
It's certainly not attractive <wink>. Guido is the Master of Syntax; if he decides the functionality is Pythonic, he'll dream up a good Pythonic syntax. I'll refrain from suggesting "if" cond "lambda" true "else" false <wink>.
Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>.
It's not that simple. People clearly want the functionality; we've seen ample evidence of that.
I have not. Really! This has been debated for nearly a decade, with no consensus (the invention of the (a and [b] or [c])[0] atrocity predates c.l.py!). *Some* people certainly want ?: (or equivalent) a lot; but others are equally opposed. Note that lack of ?: didn't have enough of a constituency in Andrew Kuchling's eyes either to make his original "Python Warts" paper, or its revisions: http://starship.python.net/crew/amk/python/writing/warts.html No change ever proposed has failed to attract vocal & persistent supporters, so it's not as simple as *that* either <0.5 wink>.
By count, I'm sure many more languages (from virtually all functional languages to Icon) use "if cond then true else false" for this purpose; obscurity is relative to your background. At least "if x then y else z" is clear on the face of it (which may betray my background <wink>). "then" has no chance of getting into Python1, though. My core objection is that ?: doesn't "look pretty": it's not at all suggestive of what it means, and the effects on precedence and associativity are unattractive ("see C, copy C" is the only sense there is to it, and rules for ?: are-- as I noted last time --obscure). Good syntax counts for a lot in Python -- which is why it doesn't look like C now. Get a good syntax, and most of my objections vanish; I don't have a good syntax to suggest, though. passing-the-ball-back-to-guido-where-he-always-knew-it- would-land<wink>-ly y'rs - tim

On Sun, 30 Jan 2000, Tim Peters wrote:
I agree with that sentiment (along the lines of the philosophy that chose "and" over "&&"), and it seems to me that it makes the most sense to use words for both: a = x > 0 then x else -x I don't have the time to do it right this second, but i suggest that a scan through a decent chunk of Python would be useful to find out how often this construct (in its "and"/"or" incarnation) actually gets used. I promise to give it a try as soon as i get my notebook battery charged up again. -- ?!ng

Ka-Ping Yee wrote:
I would favorise this as well instead of using ?: . Maybe it would make sense to be even more verbose and use an "if" as well? a = if x > 0 then x else -x sign = lambda x: if x > 0 then 1 elif x then -1 else 0 ciao - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Düppelstr. 31 : *Starship* http://starship.python.net 12163 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home

On 30 January 2000, Ka-Ping Yee said:
Yeah, I agree with Tim: it's a handy feature and I frequently wish I could do simple conditional assignment without resorting to a full-blown if/else. (I think I stumbled across "a and b or c" myself -- either that or it was suggested by *Learning Python*, but lay dormant in my subconscious for several months -- which means that I missed the "b must always be true" subtlety until it bit me. Ouch. I avoid that idiom now.) BUT the C line-noise syntax is not appropriate. It's fine in C, and it's eminently appropriate in Perl -- both languages designed to minimise wear-and-tear of programmers' keyboards. But keyboards are cheap nowadays, so perhaps we can be a bit more profligate with them. I find Ping's proposed syntax intriguing. Personally, I've always been partial to the x = if a then b else c syntax, even though I don't think I've ever used a language that includes it. (Oh wait, the toy ALGOL-knockoff that we used in Intro to Compilers had it, so I *have* written a parser and simplistic code generator for a language that includes it. Perhaps that's why I like it...) But either of these -- ie. elevate "then" to keywordhood, with or without "if", and no colons to be seen -- smell like they would play havoc with Python's grammar. And they turn a statement keyword "if" into an expression keyword. Not being at all familiar with Python's parser, I should just shut up now, but it feels tricky. And of course, any proposed syntax changes nowadays have to take JPython into account. Greg

Yes, this was in original Algol 60 and, by magic of a completely different kind, again in Algol 68 (which was a completely different language, and the Mount Everest of languages).
The solution can be the same as what Algol used: 'if' outside parentheses is a statement, and inside parentheses is an expression. It's a bit of a grammar rearrangement, but totally unambiguous. However, the added keyword means it won't be in 1.6. The lively discussion means that Eric's patch will have a hard time getting in too... --Guido van Rossum (home page: http://www.python.org/~guido/)

[Guido]
If I didn't know better <wink>, I'd say there's an actual consensus here: it seems we would all agree to "(if cond then true else false)" spelling. Not to be overlooked is Christian's enhancement, allowing "elif" too (beats all heck out of guessing how ?: nests!). Eric, are you also in agreement?
However, the added keyword means it won't be in 1.6.
I had already channeled that for the group's benefit <wink>. For 1.6, without absurd overloading of some other keyword (like "if cond def true ..."), that seems to leave (if cond: true else false) How much is that hated? I hate it myself, not least because I'd have to change IDLE's parser to guarantee it couldn't get confused by the colon here: big = ( if x >= y: x else y) Given the genesis of these things, Barry would probably have to commit similar hackery on pymode. That shouldn't drive it, but it's worth a thought. The best argument against any enhancement of this nature was Jim Fulton's argument for it: it makes lambda more attractive <wink>. BTW, I'm not entirely convinced "then" would have to be a keyword to make "if x then y else z" work: couldn't the grammar use WORD and verify it's specifically "then" later? I'm not impressed by "but that would allow 'then = (if then then else then)'!" arguments (yes, it would; no, nobody would *do* that except in an hysterical c.l.py posting <0.1 wink>).

Tim Peters <tim_one@email.msn.com>:
I'm not sure. I'm concerned that this syntax will actually be more viually confusing that ?:. That having been said, I am more interested in having ternary-select be in the language than I am in arguing about its exact syntax. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Men trained in arms from their infancy, and animated by the love of liberty, will afford neither a cheap or easy conquest. -- From the Declaration of the Continental Congress, July 1775.

On Mon, 31 Jan 2000, Tim Peters wrote:
If I didn't know better <wink>, I'd say there's an actual consensus here: it seems we would all agree to "(if cond then true else false)" spelling.
Actually, i'm afraid i don't. I initially chose the "then/else" spelling specifically because "if" flags the eye to the beginning of a statement. My line of thinking was, "'then' for expressions, 'if' for statements."
Sorry, i like that even less. It seems to abuse the colon, for the colon (to me) signals both (a) This Is A Statement and (b) This Begins A Block, neither of which are true here.
I consider this a symptom of the colon-abuse i just described...
Quite possibly, yes -- though i figured it wouldn't be *too* large an issue to make "then" a keyword, since i can't imagine anyone naming a symbol "then" except under the most freakish of circumstances. A quick check shows no symbol by that name in any of the Python scripts or modules we have here. -- ?!ng

[Tim]
[Ka-Ping Yee]
OK, I'm baffled. I probably don't recall your suggestion -- the implication is that it didn't use the word "if"? If so, I probably read it and assumed you left out the "if" my mistake <wink>. Seriously, "excessively novel" isn't called for here: *tons* of languages have used if/then/else for this purpose without difficulty. ...
... couldn't the grammar use WORD and verify it's specifically "then" later?
No keyword has been added to Python since "lambda", and you can be certain Guido will never add another (at least not to Python1) -- this is an absolute non-starter. Ping, *you* used to know this better than anyone <wink>.

On Mon, 31 Jan 2000, Tim Peters wrote:
Yeah, my suggestion was, e.g. def abs(x): return x > 0 then x else -x Might as well summarize the other suggestions so far: return x > 0 ? x else -x return x > 0 ? x : -x return if x > 0: x else -x Have i missed any? Oh, yes, and here is the control group. return x > 0 and x or -x return (x > 0 and [x] or [-x])[0] if x > 0: return x else: return -x
Yes, you're right about that.
Okay, okay. You probably have a better memory about this than i do. :) Assuming that "then" will never be made a keyword, i would probably go with "x > 0 ? x else -x". "if" seems to shout "statement" too loudly at me, and colons seem too loaded. Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"? -- ?!ng

Ka-Ping Yee <ping@lfw.org>:
Mixing ? or : with a keyword is just *ugly*. Yes, I know I said I wasn't that interested in arguing syntax, but these make my gorge rise.
return x > 0 ? x : -x
I think the other suggestions are making this one look better. At this point I have to like either this or the algol68 style Guido mentioned. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> The conclusion is thus inescapable that the history, concept, and wording of the second amendment to the Constitution of the United States, as well as its interpretation by every major commentator and court in the first half-century after its ratification, indicates that what is protected is an individual right of a private citizen to own and carry firearms in a peaceful manner. -- Report of the Subcommittee On The Constitution of the Committee On The Judiciary, United States Senate, 97th Congress, second session (February, 1982), SuDoc# Y4.J 89/2: Ar 5/5

On Mon, 31 Jan 2000, Ka-Ping Yee wrote:
Actually, Tim's memory is failing. "assert" was added in 1.5. :-) Not that this adds to the debate at all :-), but I figured that I am obligated to knock a chair leg out from under Tim every now and then. Cheers, -g p.s. I'm against a ternary operator. use an if/else statement. use def instead of lambda (lambda is the only rational basis given so far to add the operator, but it is bogus to start with) -- Greg Stein, http://www.lyra.org/

[Tim]
No keyword has been added to Python since "lambda" ...
[Greg Stein]
Actually, in 1.5 Guido *removed* lambda; then he added assert; then he had second thoughts about lambda and added it again. That's why it's the last one added. You're right: the older I get the less effective my bullshit gets <wink>. Done well, young one!
Ah, there's nothing like the smell of consensus in the morning! Except maybe napalm.

Greg Stein writes:
Actually, the places I'd use it most would be probably be in constructing parameters to string formatting operations. Grepping back in my memory, that's usually where I've wanted it. I very rarely use lambda, and usually change it on the next iteration on those cases when I do. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> Corporation for National Research Initiatives

Fred L. Drake, Jr. writes:
Boy does that ring a big bell. Was ambivalent, now I'm all for it (either C syntax or "then" syntax, don't care).
I very rarely use lambda, and usually change it on the next iteration on those cases when I do.
Use them mostly in GUIs where no smarts are required. - Gordon

Gordon McMillan wrote:
So am I! Conditional expressions make very much sense for constructing objects on-the-fly. It is quite common to denote tuples, lists and dicts directly in Python code, like so: mapping_table = { 1: "one", 2: "two", } and so on. To parameterise them, we can either use different tables embedded in an if, or use an expression inside the denotation: language = 1 mapping_table = { 1: ("one", "eins")[language], 2: ("two", "zwei")[language], } but with expressions, we get to mapping_table = { 1: language == 0 ? "one" : "eins", 2: language == 0 ? "two" : "zwei", } Well, maybe I had better chosen a different example, since the language example looks better with indexing here. How would we spell an elif? Would we at all? # languages: 0 - English 1 - German 2 - Finnish mapping_table = { 1: language == 0 ? "one" : language == 1 ? "eins", "yksi", 2: language == 0 ? "two" : language == 2 ? "zwei", "kaksi", 3: language == 0 ? "three" : language == 2 ? "drei", "kolme", } (yes the zero slot is missing - forgot what that is in Finnish:) Would conditionals also be valid on the LHS of assignments? target ? a : b = language ? "one" : "eins" grmbl - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Düppelstr. 31 : *Starship* http://starship.python.net 12163 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home

[Ping]
Yup, I *did* mentally insert an "if" for you. You're welcome <wink>.
Might as well summarize the other suggestions so far:
return x > 0 ? x else -x
Toss it -- *nobody* wants it (if that's one I suggested, I get to retract it).
return x > 0 ? x : -x
Has anyone other than Eric come out explicitly in favor of this spelling (I know others have come out in favor of a ternary operator, but don't recall much love for this syntax)?
return if x > 0: x else -x
I get to retract that too (heck, I said I hated that one in the same sentence I tossed it out ...).
Have i missed any?
Yes, the utterly conventional and perfectly clear one: return (if x > 0 then x else -x) If we don't buy into Guido's keyword argument, it's feasible. There was also some Perlish atrocity (not that I'm judging ...) like return x if x > 0 else -x
Too late: it was mine & I retracted it <wink>. "if" doesn't really *shout* stmt unless it's at the start of a line. Wrap it in parens too and it's barely a whisper.
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
The truth: "Because Guido is afraid of new keywords" <wink>.

Maybe this would be a good time to write a dozen or so examples using alternative syntaxes (syntaxii?), and stick 'em in front of a bunch of people who haven't been part of this discussion, and ask 'em "what does this do"? (Footnote: check out David Scanlan's article in the Sept. 1989 issue of "IEEE Software". Turns out that flowcharts are actually more readable than pseudocode --- the research that claimed to show otherwise was biased by (among other things) comparing structured pseudocode with spaghetti flowcharts... One li'l bit of sloppy science, and the world turns its back on something useful...) Ellipsistically yours, Greg

[Greg Wilson]
Oh, I don't know -- "visual programming" systems keep getting reinvented, so I doubt they'll be lost to us forever: executable flowcharts are at least as sensible as executable pseudocode (which latter Python partly aimed for). I'm old enough that I actually suffered many textbooks that used flowcharts. As I recall, they were absolutely worthless -- and in reviewing a few of them just now, I see that this assessment was far too generous <wink>. Lines crossing willy-nilly, dozens of single- and two(!)-letter "off page connectors", ... yikes! If the study used spaghetti flowcharts, I expect they used what was simply common practice at the time. I have seen a few good flowcharts, though, and they were cool. How about a "folding" graphical editor, so we could find & expand the logic levels of particular interest without losing the big picture ... oops-just-realized-this-has-nothing-to-do-with-1.6<wink>-ly y'rs - tim

return if x > 0 then x else -x In some contexts, parentheses must be used, e.g. (if c then a else b)[0] = 1
Hm, I was just thinking that 'then' wouldn't be the hardest keyword to add... But I should probably stick with Tim's suggestion.
But "if" is in good company.
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
Whoever proposed that was terribly confused. --Guido van Rossum (home page: http://www.python.org/~guido/)

[Tim, makes a huge production over Guido's supposed intractability on the issue of new keywords] [Guido]
Hm, I was just thinking that 'then' wouldn't be the hardest keyword to add...
Man, you *are* Unfathomable <0.9 wink>! Even if true, you should never have admitted to it <0.1 wink>.
But I should probably stick with Tim's suggestion.
Tim would. [Ping]
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
Whoever proposed that was terribly confused.
That was me. It was just brainstorming, so you wouldn't have to <wink>. i-disowned-it-in-the-same-paragraph-i-introduced-it-but- all-ideas-take-on-a-hideous-life-of-their-own-ly y'rs - tim

Greg Wilson wrote:
not in this case. quoting a leading bot implementor: "We did requirements and task analysis, iterative design, and user testing. You'd almost think emails were an interface between people and bots." and I can assure you that proving that human beings don't like weird but formally well designed syntaxes was the easy part of that project... (but don't tell the schemers ;-) </F> "Larry Wall should be shot. Along with Bill Joy and Eric Allman." -- Daniel Finster, on comp.lang.lisp "Why, just because you guys frittered away a 20-year headstart?" -- Larry Wall

[Tim]
Man, you *are* Unfathomable <0.9 wink>! Even if true, you should never have admitted to it <0.1 wink>.
[Greg Wilson]
I think that's supposed to be <wink fraction="0.9"/>, isn't it?
[Fredrik Lundh]
Right on, effbot! "Bots Helping Bots" is our motto. I'm quite sure the timbot's use of <wink> predates the Web's twisted formalization of what originally started life as a typographic device in a snail-mail newsletter, when the timbot discovered that "real people" had no idea what to make of ;-) style emoticons. User testing is exactly on target. Iterative design, too: the timbot's original use of [grin] didn't work nearly as well. The introduction of fractional winkery was actually a minor refinement, yet widely promoted by intuitionists as if it were the key idea. Feh.
Say what you will about Perl, but you gotta love Larry! I recently filed a Perl bug that was apparently introduced the day Perl5 hit the streets and somehow went unnoticed for years, and had a nice exchange with him. Looking over other recent bugs, I stumbled into this one first: @array = "0" .. -1; That, of course, computes an array of 100 elements, "0" thru "99": the string "0" gets magically autoincremented, as if it were an integer, until the *length* of the resulting string exceeds the length of the string "-1". That this wasn't justified as "a feature" gives me hope that Guido's presence on earth has done *some* little bit of good <wink>. time-for-an-oil-change-ly y'rs - tim

Ka-Ping Yee writes:
a scan through a decent chunk of Python would be useful to find out how often this construct (in its "and"/"or" incarnation) actually gets used.
I'm not sure what the survey provides other than a lower bound. I think most Python programmers who want the ?: functionality avoid the and/or approach because of the ugliness. I know I do. But I'd really like to have the functionality if the syntax is reasonable! I could live with something like "if cond then true else false"; the leading "if" is visually important; without it, you have to scan over the test expression to find the "then", and that makes it harder to read. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> Corporation for National Research Initiatives

Put me in the camp of "yeah, occasionally I wish I had it, but I can always hack around it, and the C syntax just blows". I'm sure if it's wedgeable into CPython it would also be in JPython, but I dislike ?: syntax enough to vote strongly against it for CPython 1.6. A Forth-ish syntax might be more acceptable x = y > z if y else z but come on! You'll give ordinarily dandruff-free Python programmers plenty of other reasons to scratch their heads with this one. head-and-shoulders-above-the-rest-ly y'rs, -Barry

On Mon, 31 Jan 2000, Fred L. Drake, Jr. wrote:
Good point. Just because the workaround is bad doesn't mean the thing being worked-around is unimportant... I should weigh in to say that i have really really wanted, in particular, the ability to have a condition on the right hand side of an assignement. IIR, on some occasions it seemed less clear to have to use separate statements for what was essentially a single assignment that just, eg, differed by a single term. I wanted (want) some reasonable way to express the condition in an expression. I can see how this compactness could lead to regex-style convolution of expressions, but that could be avoided by providing a not-too-terse syntax. (I should admit that may have succumbed to the (a and (b,) or (c,))[0] grotesquerie at some point! Not sure. Wish i could recall what might have justified succumbing - the mere fact that i may have, without compelling justification, might-should disqualify my judgement on the matter, ay? Hey, maybe i didn't, i was just imagining it - now am i not a sterling judge?-) Ken klm@digicool.com

Guido van Rossum wrote:
Although Eric's patch is cute, I think this language shortcut is unnecessary for Python. I'd support a do/while shortcut though ;-) It's more popular and would fit "naturally" into the language for most programmers. Overall, it seems to me that the next major version of Python needs to be cleaned, instead of being enriched. Both the language and the internals. We have enough experience already for moving in this direction. (I'm not speaking about new packages/libs or additional core facilities, like Unicode, that need to integrated). -- Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

Guido van Rossum wrote:
Yee ha! I think that this is a great idea. I'm surprised that using the colon doesn't cause problems. I'm not a grammer lawyer, and don't care that much. I very much would like to see a conditional expression. I wouldn't object if it was spelled differently than C's.
Yup. (a and (b,) or (c,))[0] is even worse. ;) Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.

Jim Fulton <jim@digicool.com>:
I'm surprised that using the colon doesn't cause problems.
Pgen doesn't tag this ambiguous. The LL(1) traversal actually helps here; by the time you see a colon, you already know whether or not you're parsing a ternary telect. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Don't think of it as `gun control', think of it as `victim disarmament'. If we make enough laws, we can all be criminals.

Jim Fulton <jim@digicool.com>:
I'm surprised that using the colon doesn't cause problems.
[ESR]
Interestingly, the very ad-hoc parsing that I described in the compiling/parsing session on devday would be hit by this... I was looking for a colon at nesting level zero. Serves me right for not using a real parse :-) --Guido van Rossum (home page: http://www.python.org/~guido/)

FWIW, the lack of a ternary select is one of the frequently asked questions in my Python courses. It would make TomC happier as well. I'm not sure the latter is a feature. =) On the topic of aesthetics, the C syntax doesn't strike me as the ultimate in pythonicity but it's not too bad either. I can't think of an alternative that doesn't involve a new reserved word. --david

Shouldn't this read #define N_TOKENS 40 ?! Apart from that I wouldn't mind having this patch in the core :-) -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/

[Guido van Rossum]
Marginal; not evil, but of minor utility.
and whether this is the right syntax.
If and only if you were a C programmer first. BTW, insert <wink>s where needed throughout <wink>.
There have always been requests for the union of all features from all other languages.
Too error prone.
Well, I'm the guy who invented that one! The thread that spawned it was just playfully wondering whether it was *possible* -- and if I didn't solve it, Majewski would have using even uglier __xxx__ trickery. I've never used it in a real program, and shoot people who do. So there is no reasonable way to spell ?: as a one-liner today, period. The question is whether that's "a lack" worth doing something about. I can live without it. Surprised that Jim (Fulton) seems so keen on it: his cPickle.c uses ?: exactly once in 4400 lines of C, and in a line that would have been clearer if C had a max function (or is it min? it can take a while to reverse-engineer the intent of a ?:! ... not good when it happens; and I recall one of the contributed patches that went into 1.5.2 longobject.c, that had Guido & I both cracking a C manual just to figure out how C would *parse* a particularly nutso blob of nested ?: thingies). If this goes in (I'm not deadly opposed, just more opposed than in favor), I'd like to see "else" used instead of the colon (cond "?" true "else" false). The question mark is reasonably mnemonic, but a colon makes no sense here. Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>. BTW, a number of other changes would be needed to the Lang Ref manual (e.g., section 2.6 (Delimeters) explicitly says that "?" isn't used in Python today, and that its appeareance outside a string literal or comment is "an unconditional error"; etc). crabby-old-man-ly y'rs - tim

Tim Peters <tim_one@email.msn.com>:
I have to say that I think any ternary syntax that mixes a single-character operator with a keyword would be intolerably ugly.
Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>.
It's not that simple. People clearly want the functionality; we've seen ample evidence of that. Given that, I think the presumption has to be in favor of using the familiar C syntax rather than an invention that would necessarily be more obscure.
I'm certainly willing to fix that. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> [The disarming of citizens] has a double effect, it palsies the hand and brutalizes the mind: a habitual disuse of physical forces totally destroys the moral [force]; and men lose at once the power of protecting themselves, and of discerning the cause of their oppression. -- Joel Barlow, "Advice to the Privileged Orders", 1792-93

I personally haven't been stunned by the ample evidence you mention. While folks do ask about the ternary select periodically in classes and on the net, none of my students at least are especially upset when I point out the readability of: if a: b = c else: b = d
The presumption from the language design point of view is to do what's right regardless of language background, not what's in C -- when Guido remembered that, he chose 'and' and 'or' over '&&' and '||'. When Guido forgot that, he chose integer division =). While all of the folks on this list are comfortable with C, I can point out that a (possibly surprisingly) large proportion of the Python programmers I have taught have never used C or never felt comfortable with it. If CP4E succeeds, that proportion will grow, not shrink. I do think that taking a page from Randy Pausch would be a good idea in this case. My guess is that english words would emerge from trying to teach non-programmers the concept, but I of course don't have data on the topic. I wonder how high-school teachers teach the hook-colon in C intro classes, specifically what _words_ they use. Those words might lead to alternative syntaxes. Finally, something at the edge of my brain is trying to combine the logic of the ternary select (which is clearly related to control flow) and a more generalized switch statement. But I'm not seeing anything syntactically appealing at present. That said, the hook-colon syntax is appealing from a release management perspective because it fits within the current set of reserved words and clearly isn't the hardest concept to teach. --david

The question comes from what "problem" you're trying to solve. The ?: syntax does not introduce any new "functionality" to the language, nor does it make it capable of solving problems or requirements that it can not do at the current time. The second qustion I'd ask is, who is this aimed at? It's certainly not aimed at first-time programmers, as I know from experience that the ?: is one of the hardest things to teach people in C (after pointers), and often I leave it out of training when I did it. It's simply a "shorthand" not a new functionality. If its aimed at experienced programmers, I'd argue that it's at best "non-pythonic" and at worst a hack, taken from a language in which it exposes the "macro assembler" approach. Python is not a language that has been optimized for "minimal typing", it's much more verbose than most languages, and so that argument shouldn' be applied. Perhaps it's for optimization? That was I believe the original argument made for it in K&R, in that optimizers in that day were rather antiquated, wheras today, I believe that any C compiler would get it right if it were expressed in its full form. (Timbot?) So, it comes down to a few questions for me: Does it solve a new problem? No Is it pythonic? No Does it make it faster? No Given Pyton's CP4E goals, and its general place as an easy to use language, I'd argue this patch would be counter to all of those goals. Sorry if I pushed someone's buton, but... I saw a lot of hints at making Python MUCH more complex, which is counter to why I changed and dropped many other languags. Chris -- | Christopher Petrilli | petrilli@amber.org

Christopher Petrilli <petrilli@amber.org>:
Well, in a theoretical sense, you're right. But then, even troff macros and INTERCAL are Turing-complete <my-first-attempt-at-a-Tim-Peters-style-wink>. One of the lessons of Python to this old LISPer is that *notation matters*. Theoretically, Python is a subset of Scheme-with-objects using a vaguely C-like surface notation. But even I would rather write a for-loop than the equivalent recursion. That's why I code in Python now instead of trying to rescue LISP from its desuetitude. So while it is *theoretically* true that ?: adds nothing, it is *practically* true that it enables a large class of idioms that can't otherwise be comfortably expressed. That matters. Now, you can argue that the complexity ?: adds to language is not paid for by the additional convenience; I disagree, but that's at least a defensible argument. But simply saying it "adds nothing to the language" is a red herring -- neither do many of the other base language features. Why, for example, do we have more than one kind of loop construct? Unecessary. Wasteful. Clearly either "for" or "while" must go. As an exercise, try editing your complaint so that it refers to "for" everywhere it now refers to ?:. Contemplate the edited version until you achieve enlightenment ;-). -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> The same applies for other kinds of long-lasting low-level pain. [...] The body's response to being jabbed, pierced, and cut is to produce endorphins. [...] So here's my programme for breaking that cycle of dependency on Windows: get left arm tattooed with dragon motif, buy a crate of Jamaican Hot! Pepper Sauce, get nipples pierced. With any luck that will produce enough endorphins to make Windows completely redundant, and I can then upgrade to Linux and get on with things. -- Pieter Hintjens

[Christopher Petrilli]
Concise expression of common concepts is a Good Thing, though, and there's nothing inherently evil about wanting one of two outcomes <wink>. My impression is that the people historically most in favor of ?: ("or something like it") are also the ones most strongly in favor of embedded assignment ("or something like it"), and I can't *dismiss* either gripe. The Python while 1: x = something_or_other() if not x: break consume(x) idiom is truly grating at first -- more so than the multi-line ?: alternatives, in my eyes.
Indeed, a couple weeks ago we tracked down a "mysterious slowdown" of our core speech recognizer to a particular compiler failing to optimize *unless* we changed a ?: into a long winded if/else! There's really nothing you can say about "any C compiler" -- optimization is much more a black art than anyone in that business will admit to in public <0.9 wink>. C was definitely designed with "by hand" optimization in mind, and, ironically, it's those features (particularly pointer aliasing) that make it harder for compilers to optimize than is, say, Fortran. But regardless of origin, ?: stands or falls on its other merits now. Python's own implementation uses it often enough, and to good effect. So it can't be that Guido hates the idea <wink>. It's just hard to love the syntax.
Would a nice syntax allow clearer expression of some common computations? Probably yes. That's the same basis on which, e.g., list.pop and list.extend and dict.get and 3-argument getattr and ... were adopted. "Faster" applied to those too, but nobody pushed for 'em on that basis. Clearer! That's what really matters. It's the same argument for list comprehensions too.
A good antitode to feature panic is reviewing Misc/HISTORY: Guido's willingness to entertain suggestions far exceeds his willingness to adopt them <wink>. it-would-be-different-if-features-were-just-as-easy-to- take-out-ly y'rs - tim

Christopher Petrilli wrote:
The question comes from what "problem" you're trying to solve.
It would allow you to incorporate logic into expressions. There are contexts where only expressions are allowed, such as: - lambdas - DTML expr attributes in which I'd very much like to incorporate tests.
The ?: syntax does not introduce any new "functionality" to the language,
Yes it does.
Ditto.
Hm. I can't agree. Smalltalk, came out of an essentially CP4E effort two decades ago at Xerox PARC. Smalltalk *only* had conditional expressions. The message: [condition] ifTrue: [do something ...] ifFalse: [do something else ...] is an expression in Smalltalk.
No, it allows testing in expressions.
I don't agree.
Python is not a language that has been optimized for "minimal typing",
That's not the issue.
Yes.
Is it pythonic? No
Pythonicity is relative.
Does it make it faster? No
Who cares? Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.

Don't know much about DTML, but believe that being able to put conditionals in lambdas would make the latter much more useful.
Is anything possible with ?: that's impossible without? No --- Python is Turing-equivalent before and after the change. Is anything easier with ?: --- yes. Does this make up for the added complexity? Dunno (see below).
Strongly agree with the first author --- IME, ?: is very hard to teach. Greg

On Mon, 31 Jan 2000 gvwilson@nevex.com wrote:
Giving Guido one less reason to dislike ?: <wink> Seriously, I disagree with the basic premise of you and Jim: you can *already* have control structures inside experessions with and/or, so even for Jim's twisted meanings for "add new functionality to the language" it's not true.
Is anything easier with ?: --- yes.
For the reader, for the writer or for the cp4e-newbie learning Python? cluttering-another-mailing-list-ly y'rs, Z. -- Moshe Zadka <mzadka@geocities.com>. INTERNET: Learn what you know. Share what you don't.

Moshe Zadka <moshez@math.huji.ac.il>:
You laugh, but this was in fact in my mind. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Nearly all men can stand adversity, but if you want to test a man's character, give him power. -- Abraham Lincoln

Have you ever tried to teach this to relatively experienced programmers (never mind novices) whose background is Fortran, Modula-2, Ada, or anything other than C/C++/Java? It's *really* hard to get the idea across. I tried it in the first Python course I taught at LANL, and wound up spending 15 minutes trying to unconfuse people (and failed). Afterward, one guy said that it made even less sense than using integer offsets to fake linked lists in Fortran-77... Greg

On Mon, 31 Jan 2000 gvwilson@nevex.com wrote:
<but it's hard to get the idea across> You're most certainly right. This, however, refers to usability, not functionality. It makes existing functionality usable by non-timbots. A worthy goal, but it's not the same as adding new functionality. -- Moshe Zadka <mzadka@geocities.com>. INTERNET: Learn what you know. Share what you don't.

[Tim, tosses off cond "?" true "else" false in apparent hatred of colons] [Eric S. Raymond]
I have to say that I think any ternary syntax that mixes a single-character operator with a keyword would be intolerably ugly.
It's certainly not attractive <wink>. Guido is the Master of Syntax; if he decides the functionality is Pythonic, he'll dream up a good Pythonic syntax. I'll refrain from suggesting "if" cond "lambda" true "else" false <wink>.
Now let's see whether people really want the functionality or are just addicted to C syntax <ahem>.
It's not that simple. People clearly want the functionality; we've seen ample evidence of that.
I have not. Really! This has been debated for nearly a decade, with no consensus (the invention of the (a and [b] or [c])[0] atrocity predates c.l.py!). *Some* people certainly want ?: (or equivalent) a lot; but others are equally opposed. Note that lack of ?: didn't have enough of a constituency in Andrew Kuchling's eyes either to make his original "Python Warts" paper, or its revisions: http://starship.python.net/crew/amk/python/writing/warts.html No change ever proposed has failed to attract vocal & persistent supporters, so it's not as simple as *that* either <0.5 wink>.
By count, I'm sure many more languages (from virtually all functional languages to Icon) use "if cond then true else false" for this purpose; obscurity is relative to your background. At least "if x then y else z" is clear on the face of it (which may betray my background <wink>). "then" has no chance of getting into Python1, though. My core objection is that ?: doesn't "look pretty": it's not at all suggestive of what it means, and the effects on precedence and associativity are unattractive ("see C, copy C" is the only sense there is to it, and rules for ?: are-- as I noted last time --obscure). Good syntax counts for a lot in Python -- which is why it doesn't look like C now. Get a good syntax, and most of my objections vanish; I don't have a good syntax to suggest, though. passing-the-ball-back-to-guido-where-he-always-knew-it- would-land<wink>-ly y'rs - tim

On Sun, 30 Jan 2000, Tim Peters wrote:
I agree with that sentiment (along the lines of the philosophy that chose "and" over "&&"), and it seems to me that it makes the most sense to use words for both: a = x > 0 then x else -x I don't have the time to do it right this second, but i suggest that a scan through a decent chunk of Python would be useful to find out how often this construct (in its "and"/"or" incarnation) actually gets used. I promise to give it a try as soon as i get my notebook battery charged up again. -- ?!ng

Ka-Ping Yee wrote:
I would favorise this as well instead of using ?: . Maybe it would make sense to be even more verbose and use an "if" as well? a = if x > 0 then x else -x sign = lambda x: if x > 0 then 1 elif x then -1 else 0 ciao - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Düppelstr. 31 : *Starship* http://starship.python.net 12163 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home

On 30 January 2000, Ka-Ping Yee said:
Yeah, I agree with Tim: it's a handy feature and I frequently wish I could do simple conditional assignment without resorting to a full-blown if/else. (I think I stumbled across "a and b or c" myself -- either that or it was suggested by *Learning Python*, but lay dormant in my subconscious for several months -- which means that I missed the "b must always be true" subtlety until it bit me. Ouch. I avoid that idiom now.) BUT the C line-noise syntax is not appropriate. It's fine in C, and it's eminently appropriate in Perl -- both languages designed to minimise wear-and-tear of programmers' keyboards. But keyboards are cheap nowadays, so perhaps we can be a bit more profligate with them. I find Ping's proposed syntax intriguing. Personally, I've always been partial to the x = if a then b else c syntax, even though I don't think I've ever used a language that includes it. (Oh wait, the toy ALGOL-knockoff that we used in Intro to Compilers had it, so I *have* written a parser and simplistic code generator for a language that includes it. Perhaps that's why I like it...) But either of these -- ie. elevate "then" to keywordhood, with or without "if", and no colons to be seen -- smell like they would play havoc with Python's grammar. And they turn a statement keyword "if" into an expression keyword. Not being at all familiar with Python's parser, I should just shut up now, but it feels tricky. And of course, any proposed syntax changes nowadays have to take JPython into account. Greg

Yes, this was in original Algol 60 and, by magic of a completely different kind, again in Algol 68 (which was a completely different language, and the Mount Everest of languages).
The solution can be the same as what Algol used: 'if' outside parentheses is a statement, and inside parentheses is an expression. It's a bit of a grammar rearrangement, but totally unambiguous. However, the added keyword means it won't be in 1.6. The lively discussion means that Eric's patch will have a hard time getting in too... --Guido van Rossum (home page: http://www.python.org/~guido/)

[Guido]
If I didn't know better <wink>, I'd say there's an actual consensus here: it seems we would all agree to "(if cond then true else false)" spelling. Not to be overlooked is Christian's enhancement, allowing "elif" too (beats all heck out of guessing how ?: nests!). Eric, are you also in agreement?
However, the added keyword means it won't be in 1.6.
I had already channeled that for the group's benefit <wink>. For 1.6, without absurd overloading of some other keyword (like "if cond def true ..."), that seems to leave (if cond: true else false) How much is that hated? I hate it myself, not least because I'd have to change IDLE's parser to guarantee it couldn't get confused by the colon here: big = ( if x >= y: x else y) Given the genesis of these things, Barry would probably have to commit similar hackery on pymode. That shouldn't drive it, but it's worth a thought. The best argument against any enhancement of this nature was Jim Fulton's argument for it: it makes lambda more attractive <wink>. BTW, I'm not entirely convinced "then" would have to be a keyword to make "if x then y else z" work: couldn't the grammar use WORD and verify it's specifically "then" later? I'm not impressed by "but that would allow 'then = (if then then else then)'!" arguments (yes, it would; no, nobody would *do* that except in an hysterical c.l.py posting <0.1 wink>).

Tim Peters <tim_one@email.msn.com>:
I'm not sure. I'm concerned that this syntax will actually be more viually confusing that ?:. That having been said, I am more interested in having ternary-select be in the language than I am in arguing about its exact syntax. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> Men trained in arms from their infancy, and animated by the love of liberty, will afford neither a cheap or easy conquest. -- From the Declaration of the Continental Congress, July 1775.

On Mon, 31 Jan 2000, Tim Peters wrote:
If I didn't know better <wink>, I'd say there's an actual consensus here: it seems we would all agree to "(if cond then true else false)" spelling.
Actually, i'm afraid i don't. I initially chose the "then/else" spelling specifically because "if" flags the eye to the beginning of a statement. My line of thinking was, "'then' for expressions, 'if' for statements."
Sorry, i like that even less. It seems to abuse the colon, for the colon (to me) signals both (a) This Is A Statement and (b) This Begins A Block, neither of which are true here.
I consider this a symptom of the colon-abuse i just described...
Quite possibly, yes -- though i figured it wouldn't be *too* large an issue to make "then" a keyword, since i can't imagine anyone naming a symbol "then" except under the most freakish of circumstances. A quick check shows no symbol by that name in any of the Python scripts or modules we have here. -- ?!ng

[Tim]
[Ka-Ping Yee]
OK, I'm baffled. I probably don't recall your suggestion -- the implication is that it didn't use the word "if"? If so, I probably read it and assumed you left out the "if" my mistake <wink>. Seriously, "excessively novel" isn't called for here: *tons* of languages have used if/then/else for this purpose without difficulty. ...
... couldn't the grammar use WORD and verify it's specifically "then" later?
No keyword has been added to Python since "lambda", and you can be certain Guido will never add another (at least not to Python1) -- this is an absolute non-starter. Ping, *you* used to know this better than anyone <wink>.

On Mon, 31 Jan 2000, Tim Peters wrote:
Yeah, my suggestion was, e.g. def abs(x): return x > 0 then x else -x Might as well summarize the other suggestions so far: return x > 0 ? x else -x return x > 0 ? x : -x return if x > 0: x else -x Have i missed any? Oh, yes, and here is the control group. return x > 0 and x or -x return (x > 0 and [x] or [-x])[0] if x > 0: return x else: return -x
Yes, you're right about that.
Okay, okay. You probably have a better memory about this than i do. :) Assuming that "then" will never be made a keyword, i would probably go with "x > 0 ? x else -x". "if" seems to shout "statement" too loudly at me, and colons seem too loaded. Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"? -- ?!ng

Ka-Ping Yee <ping@lfw.org>:
Mixing ? or : with a keyword is just *ugly*. Yes, I know I said I wasn't that interested in arguing syntax, but these make my gorge rise.
return x > 0 ? x : -x
I think the other suggestions are making this one look better. At this point I have to like either this or the algol68 style Guido mentioned. -- <a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a> The conclusion is thus inescapable that the history, concept, and wording of the second amendment to the Constitution of the United States, as well as its interpretation by every major commentator and court in the first half-century after its ratification, indicates that what is protected is an individual right of a private citizen to own and carry firearms in a peaceful manner. -- Report of the Subcommittee On The Constitution of the Committee On The Judiciary, United States Senate, 97th Congress, second session (February, 1982), SuDoc# Y4.J 89/2: Ar 5/5

On Mon, 31 Jan 2000, Ka-Ping Yee wrote:
Actually, Tim's memory is failing. "assert" was added in 1.5. :-) Not that this adds to the debate at all :-), but I figured that I am obligated to knock a chair leg out from under Tim every now and then. Cheers, -g p.s. I'm against a ternary operator. use an if/else statement. use def instead of lambda (lambda is the only rational basis given so far to add the operator, but it is bogus to start with) -- Greg Stein, http://www.lyra.org/

[Tim]
No keyword has been added to Python since "lambda" ...
[Greg Stein]
Actually, in 1.5 Guido *removed* lambda; then he added assert; then he had second thoughts about lambda and added it again. That's why it's the last one added. You're right: the older I get the less effective my bullshit gets <wink>. Done well, young one!
Ah, there's nothing like the smell of consensus in the morning! Except maybe napalm.

Greg Stein writes:
Actually, the places I'd use it most would be probably be in constructing parameters to string formatting operations. Grepping back in my memory, that's usually where I've wanted it. I very rarely use lambda, and usually change it on the next iteration on those cases when I do. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> Corporation for National Research Initiatives

Fred L. Drake, Jr. writes:
Boy does that ring a big bell. Was ambivalent, now I'm all for it (either C syntax or "then" syntax, don't care).
I very rarely use lambda, and usually change it on the next iteration on those cases when I do.
Use them mostly in GUIs where no smarts are required. - Gordon

Gordon McMillan wrote:
So am I! Conditional expressions make very much sense for constructing objects on-the-fly. It is quite common to denote tuples, lists and dicts directly in Python code, like so: mapping_table = { 1: "one", 2: "two", } and so on. To parameterise them, we can either use different tables embedded in an if, or use an expression inside the denotation: language = 1 mapping_table = { 1: ("one", "eins")[language], 2: ("two", "zwei")[language], } but with expressions, we get to mapping_table = { 1: language == 0 ? "one" : "eins", 2: language == 0 ? "two" : "zwei", } Well, maybe I had better chosen a different example, since the language example looks better with indexing here. How would we spell an elif? Would we at all? # languages: 0 - English 1 - German 2 - Finnish mapping_table = { 1: language == 0 ? "one" : language == 1 ? "eins", "yksi", 2: language == 0 ? "two" : language == 2 ? "zwei", "kaksi", 3: language == 0 ? "three" : language == 2 ? "drei", "kolme", } (yes the zero slot is missing - forgot what that is in Finnish:) Would conditionals also be valid on the LHS of assignments? target ? a : b = language ? "one" : "eins" grmbl - chris -- Christian Tismer :^) <mailto:tismer@appliedbiometrics.com> Applied Biometrics GmbH : Have a break! Take a ride on Python's Düppelstr. 31 : *Starship* http://starship.python.net 12163 Berlin : PGP key -> http://wwwkeys.pgp.net PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF we're tired of banana software - shipped green, ripens at home

[Ping]
Yup, I *did* mentally insert an "if" for you. You're welcome <wink>.
Might as well summarize the other suggestions so far:
return x > 0 ? x else -x
Toss it -- *nobody* wants it (if that's one I suggested, I get to retract it).
return x > 0 ? x : -x
Has anyone other than Eric come out explicitly in favor of this spelling (I know others have come out in favor of a ternary operator, but don't recall much love for this syntax)?
return if x > 0: x else -x
I get to retract that too (heck, I said I hated that one in the same sentence I tossed it out ...).
Have i missed any?
Yes, the utterly conventional and perfectly clear one: return (if x > 0 then x else -x) If we don't buy into Guido's keyword argument, it's feasible. There was also some Perlish atrocity (not that I'm judging ...) like return x if x > 0 else -x
Too late: it was mine & I retracted it <wink>. "if" doesn't really *shout* stmt unless it's at the start of a line. Wrap it in parens too and it's barely a whisper.
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
The truth: "Because Guido is afraid of new keywords" <wink>.

Maybe this would be a good time to write a dozen or so examples using alternative syntaxes (syntaxii?), and stick 'em in front of a bunch of people who haven't been part of this discussion, and ask 'em "what does this do"? (Footnote: check out David Scanlan's article in the Sept. 1989 issue of "IEEE Software". Turns out that flowcharts are actually more readable than pseudocode --- the research that claimed to show otherwise was biased by (among other things) comparing structured pseudocode with spaghetti flowcharts... One li'l bit of sloppy science, and the world turns its back on something useful...) Ellipsistically yours, Greg

[Greg Wilson]
Oh, I don't know -- "visual programming" systems keep getting reinvented, so I doubt they'll be lost to us forever: executable flowcharts are at least as sensible as executable pseudocode (which latter Python partly aimed for). I'm old enough that I actually suffered many textbooks that used flowcharts. As I recall, they were absolutely worthless -- and in reviewing a few of them just now, I see that this assessment was far too generous <wink>. Lines crossing willy-nilly, dozens of single- and two(!)-letter "off page connectors", ... yikes! If the study used spaghetti flowcharts, I expect they used what was simply common practice at the time. I have seen a few good flowcharts, though, and they were cool. How about a "folding" graphical editor, so we could find & expand the logic levels of particular interest without losing the big picture ... oops-just-realized-this-has-nothing-to-do-with-1.6<wink>-ly y'rs - tim

return if x > 0 then x else -x In some contexts, parentheses must be used, e.g. (if c then a else b)[0] = 1
Hm, I was just thinking that 'then' wouldn't be the hardest keyword to add... But I should probably stick with Tim's suggestion.
But "if" is in good company.
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
Whoever proposed that was terribly confused. --Guido van Rossum (home page: http://www.python.org/~guido/)

[Tim, makes a huge production over Guido's supposed intractability on the issue of new keywords] [Guido]
Hm, I was just thinking that 'then' wouldn't be the hardest keyword to add...
Man, you *are* Unfathomable <0.9 wink>! Even if true, you should never have admitted to it <0.1 wink>.
But I should probably stick with Tim's suggestion.
Tim would. [Ping]
Another issue with the last suggestion: how do you explain putting a colon after the condition but not after the "else"?
Whoever proposed that was terribly confused.
That was me. It was just brainstorming, so you wouldn't have to <wink>. i-disowned-it-in-the-same-paragraph-i-introduced-it-but- all-ideas-take-on-a-hideous-life-of-their-own-ly y'rs - tim

Greg Wilson wrote:
not in this case. quoting a leading bot implementor: "We did requirements and task analysis, iterative design, and user testing. You'd almost think emails were an interface between people and bots." and I can assure you that proving that human beings don't like weird but formally well designed syntaxes was the easy part of that project... (but don't tell the schemers ;-) </F> "Larry Wall should be shot. Along with Bill Joy and Eric Allman." -- Daniel Finster, on comp.lang.lisp "Why, just because you guys frittered away a 20-year headstart?" -- Larry Wall

[Tim]
Man, you *are* Unfathomable <0.9 wink>! Even if true, you should never have admitted to it <0.1 wink>.
[Greg Wilson]
I think that's supposed to be <wink fraction="0.9"/>, isn't it?
[Fredrik Lundh]
Right on, effbot! "Bots Helping Bots" is our motto. I'm quite sure the timbot's use of <wink> predates the Web's twisted formalization of what originally started life as a typographic device in a snail-mail newsletter, when the timbot discovered that "real people" had no idea what to make of ;-) style emoticons. User testing is exactly on target. Iterative design, too: the timbot's original use of [grin] didn't work nearly as well. The introduction of fractional winkery was actually a minor refinement, yet widely promoted by intuitionists as if it were the key idea. Feh.
Say what you will about Perl, but you gotta love Larry! I recently filed a Perl bug that was apparently introduced the day Perl5 hit the streets and somehow went unnoticed for years, and had a nice exchange with him. Looking over other recent bugs, I stumbled into this one first: @array = "0" .. -1; That, of course, computes an array of 100 elements, "0" thru "99": the string "0" gets magically autoincremented, as if it were an integer, until the *length* of the resulting string exceeds the length of the string "-1". That this wasn't justified as "a feature" gives me hope that Guido's presence on earth has done *some* little bit of good <wink>. time-for-an-oil-change-ly y'rs - tim

Ka-Ping Yee writes:
a scan through a decent chunk of Python would be useful to find out how often this construct (in its "and"/"or" incarnation) actually gets used.
I'm not sure what the survey provides other than a lower bound. I think most Python programmers who want the ?: functionality avoid the and/or approach because of the ugliness. I know I do. But I'd really like to have the functionality if the syntax is reasonable! I could live with something like "if cond then true else false"; the leading "if" is visually important; without it, you have to scan over the test expression to find the "then", and that makes it harder to read. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> Corporation for National Research Initiatives

Put me in the camp of "yeah, occasionally I wish I had it, but I can always hack around it, and the C syntax just blows". I'm sure if it's wedgeable into CPython it would also be in JPython, but I dislike ?: syntax enough to vote strongly against it for CPython 1.6. A Forth-ish syntax might be more acceptable x = y > z if y else z but come on! You'll give ordinarily dandruff-free Python programmers plenty of other reasons to scratch their heads with this one. head-and-shoulders-above-the-rest-ly y'rs, -Barry

On Mon, 31 Jan 2000, Fred L. Drake, Jr. wrote:
Good point. Just because the workaround is bad doesn't mean the thing being worked-around is unimportant... I should weigh in to say that i have really really wanted, in particular, the ability to have a condition on the right hand side of an assignement. IIR, on some occasions it seemed less clear to have to use separate statements for what was essentially a single assignment that just, eg, differed by a single term. I wanted (want) some reasonable way to express the condition in an expression. I can see how this compactness could lead to regex-style convolution of expressions, but that could be avoided by providing a not-too-terse syntax. (I should admit that may have succumbed to the (a and (b,) or (c,))[0] grotesquerie at some point! Not sure. Wish i could recall what might have justified succumbing - the mere fact that i may have, without compelling justification, might-should disqualify my judgement on the matter, ay? Hey, maybe i didn't, i was just imagining it - now am i not a sterling judge?-) Ken klm@digicool.com

Guido van Rossum wrote:
Although Eric's patch is cute, I think this language shortcut is unnecessary for Python. I'd support a do/while shortcut though ;-) It's more popular and would fit "naturally" into the language for most programmers. Overall, it seems to me that the next major version of Python needs to be cleaned, instead of being enriched. Both the language and the internals. We have enough experience already for moving in this direction. (I'm not speaking about new packages/libs or additional core facilities, like Unicode, that need to integrated). -- Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252
participants (20)
-
Barry A. Warsaw
-
Christian Tismer
-
Christopher Petrilli
-
David Ascher
-
David Ascher
-
Eric S. Raymond
-
Fred L. Drake, Jr.
-
Fredrik Lundh
-
Gordon McMillan
-
Greg Stein
-
Greg Ward
-
Guido van Rossum
-
gvwilson@nevex.com
-
Jim Fulton
-
Ka-Ping Yee
-
Ken Manheimer
-
M.-A. Lemburg
-
Moshe Zadka
-
Tim Peters
-
Vladimir Marangozov