[Python-ideas] Statements vs Expressions... why?

Bruce Leban bruce at leapyear.org
Fri Sep 12 00:14:40 CEST 2008

I agree that making every statement also an expression has merits, as does
FP. However, you're handwaving about how this fits into python. The scope of
an if is defined syntactically by indentation. Your proposal changes that in
some way that I can't quite tell. Is it that you can put a single expression
between the if and the else? Or something else? When would line breaks be
optional where they are now required?
Simply saying "make everything an expression" is insufficient. Saying "it's
just lifting a restriction" is also insufficient. In many languages there
are restrictions on using the + operators with non-numbers. Why can't we
just remove that restriction? Well, we have to define the precise semantics
in order to do that, e.g., what does []+{} mean?

You said that the value of a for loop would have the value [] if it didn't
include yield, i.e.,
    for x in y: foo(x)
evaluates to [] while you said
    if x: foo(x) else: foo(0)
evaluates to foo(something). That seems inconsistent. Is that inconsistency
a good thing? For that matter, why return a list rather than () or an empty
generator? [[As an aside: why can't I write {foo(x) for x in y} which is the
equivalent of doing d[x] = foo(x) for all x. I've just written the
equivalent loop several times recently.]]

To answer these questions, the right thing to do is to write a list of
exactly what new syntax and semantics you are proposing. I'm not saying that
I (or anyone else) will agree with what you propose but I certainly can't
agree with the vague proposal you've made so far.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080911/84352fb4/attachment.html>

More information about the Python-ideas mailing list