multi-statement lines ( why can't I ... )

Chris Hoffmann (choffman@vicorp.com)
Fri, 10 Dec 93 16:18:43 EST

>> Why can't I use a multi-statement line like:
>>
>> >>>for x in list: if x[:len(key)] == key : print x
>>
>> without getting an invalid syntax message ?
>>
>>
>> I could live without the whole statement on one line,
>> but I would LIKE to have the selector statements be
>> one line, as in:
>>
>> >>>for x in list: if testof(x) :
>> ... do_somthing
>>
>> as it makes it clear at the top that I'm only processing
>> a subset of list ( and it keeps me from requesting NEW
>> keywords like "from x in list *with* ... " or something
>> equally bizarre! :-)
>>
>>
>> - - Steve M.

This seems as good a time as any to point out a problem I see with
Python. While most Python programmers seem to like the use of
indentation to show nesting, almost without fail the first thing
people complain about when I show them Python is this reliance on
indentation. I've also seen at least one complaint in some newsgroup
as well.

Personally, although I liked it at first, I've come to see it as a
mixed blessing. My biggest problem is when you jump up several nesting
levels at the end of a block. Without a "}" or "end" it's hard to tell
just what level you're returning to. It's also makes editing in emacs
harder as there's nothing for it to latch on to when doing
auto-indenting.

Sure, you can throw an "# end if" comment in to keep track of the
level, but if you're going to do that, why not have something that has
meaning to Python (and emacs).

What I'd like is an _optional_ bracketing construct, so Steven's
statement could be written as:

>>>for x in list: begin if x[:len(key)] == key : print x; end

Within the bracketing construct indentation is no longer significant.
Outside everthing between begin and end is treated as a single
statement.

I'm not sure whether indentation mode could be able to be turned on
again inside the block. For example:

for x in list: begin if x[:len(key)] == key :
print x
print key
end

Since there is no "begin" after the "if" statement perhaps a change of
indentation can become significant. Except I'm not sure how you return
to indentation-insensitive mode.

Chris

-----------------------------------------------------------------------------
Chris Hoffmann VI Corporation
choffman@vicorp.com 47 Pleasant St. Northampton MA 01060