[Python-ideas] Statements vs Expressions... why?
bruce at leapyear.org
Sat Sep 13 21:27:06 CEST 2008
On Sat, Sep 13, 2008 at 9:02 AM, Cliff Wells <cliff at develix.com> wrote:
> Let's use your example from above: a+b vs add(a, b)
> a + b is the *exact* semantical equivalent of add(a, b). They do the
> same thing, they can be used in the same contexts. The + operator is
> pure semantic sugar (and well-used sugar too).
First, + is *syntactic* sugar not semantic sugar. Syntactic sugar is
something that changes the appearance but not the semantics.
C uses semicolons and Python doesn't. Is that syntactic sugar? Can I just
ask C to remove the "restriction" that semicolons are required without
defining precisely what that means? If I do, then I end up with something
Now let's imagine things aren't quite so equivalent. a+b has the same
> result as add(a, b), except you can only use the + operator in one
> particular context: assignment. It cannot be used say, with a comparison
> So in my imaginary Python, this is legal
> x = 1 + 2
> but this is not
> if x < y + 1: pass
> and must instead be written
> if x < add(y, 1): pass
This is a strawman. You hypothesize that + would only be usable in the
context of "assignment". But that's not the context. The context is
expression. The semantics are the same.
Here's a real example: consider a language where +, *, etc. can only be used
in the context of augmented assignment. That is:
a += b
c *= d
etc. while I have to use functional syntax everywhere else:
x = add(a,b)
y = mul(c,d)
etc. Now I propose improving this language by eliminating the "restriction"
that +, * etc. can only be used in assignments.
You ask me to define the syntax and semantics of these operators and I brush
that off as unimportant. All I'm advocating is "lifting a restriction" in
the language. I'm unifying syntax not adding complexity, right? No need to
explain pesky details.
No. That's ridiculous. You might be surprised when you use my new features
x = 2 * 3 + 4
y = 2 - 3 + 4
sets x to 14 and y to -5 but that's not my fault. (And lest you say this is
a strawman and no one would consider any value other than 10 and 3, go look
This is what you're doing. If you can't precisely define how the language is
different with your proposed change, then it's not worth discussing. You can
do that with a formal definition as I suggested or by actually implementing
your changes as Guido suggested. You can't do it by insisting that no one
understands what you're talking about.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas