a = b = 1 just syntactic sugar?

Ed Avis ed at membled.com
Sat Jun 7 23:53:35 CEST 2003

"Terry Reedy" <tjreedy at udel.edu> writes:

>He consciously choose the heterogenous mixture of statements and
>expression as being more conducive to his goal of readability,
>especially for beginners.

I'm not trying to attack the distinction between expressions and
statements.  I know better than to do that.  I am just asking, why is
it that the body of an anonymous function cannot contain statements?

The fact that the expression / statement distinction exists is not in
itself a reason to prohibit statements from appearing in anonymous

>Expressions, but not statements, are used in assignment statements,
>operator expressions, conditions, function calls, collection
>indexing, and, yes, also in lambdas.  Making a singular exception for
>lambdas would definitely complexify the language.

You think so?  To me it looks more like a case of

'Statements, not expressions, are used in function bodies, for the
'main program' and for commands typed into the Python interpreter.
Making a singular exception for anonymous functions would definitely
complexify the language.'

Do you think that prohibiting statements inside lamda bodies follows
the principle of least surprise?

>>If a clear and simple syntax can be worked out to
>This is a big if.  No one that I know of has yet done so of in years
>of discussion.

Elsewhere in this thread I proposed using a simple_stmt as the body of
a lambda.  Still, if you say there has been years of discussion I am
not so foolish as to think I've found the answer.

>If substitutivity were general, then Python would be quite different
>from what it is.

I didn't argue for general substitutivity or for abolishing the
statement/expression distinction, only for allowing statements inside
lambda-functions, as they can appear inside named functions.  But I
accept that multi-line lambda definitions would be too awkward.

>>I think that the rule of 'anything that fits on one line'  is such
>>a simple rule
>Simple?  'line' is not a syntactic category

It seems to me from the Python grammar that the production simple_stmt
is a statement that fits on one line.

>In either case, you are proposing a new syntactic category of
>'pseudoline'.  Would you allow them to contain multiple statements,
>separated by ';', like real lines?

No no.  I know that these are all favourite topics on the Python
newsgroup - assignment as expression - multiline statements with ; -
written block delimiters - perhaps deliberately mentioned by astute
trolls who know how to get certain residents excited.  But I am not
advocating any of that.  Just one small and seemingly simple change,
to let a single line of code be used as the body of an anonymous
function rather than only expressions as at present.

Ed Avis <ed at membled.com>

More information about the Python-list mailing list