The use of :

Jeremy Bowers jerf at
Mon Nov 29 06:11:44 CET 2004

On Sun, 28 Nov 2004 19:17:52 +0000, gabriele renzi wrote:
> are they really?
> if <expression> <expressions>
> and the likes would invho parse just fine

if "" "a" print "Hi"

Does that print Hi or not?

Dig deeper into Python grammar; make sure you know that statements and
expressions are different, and the counter-example above is based on
Python's string concatenation rules:

Python 2.3.4 (#1, Oct 26 2004, 20:13:42) 
[GCC 3.4.2  (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "a" "b"

The question is, what is the "<expression>", "" or "" "a"? The first is
false, the second true.

(At this point the natural response of many people is to start adding
rules and exceptions and "well, obviously"s... but none of them will beat
if <expression>:, or justify the removal of a colon if you compare back
to the original; that's the *real* competition. This is just a pre-emptive
point 'cause I've seen people do this sort of thing too often, it isn't
targetted directly at you, gabriele.)

A completely new grammar could certainly do away with it and there are
languages that can do that, but you almost certainly won't be able to get
there from here via incremental changes. (Forth is close but it is spelled
differently. Lisp natually encapsulates all expressions; I don't think it
quite captures the spirit of what I think you're getting at, but for the
Lisp definition of "expression", it works.)

More information about the Python-list mailing list