a = b = 1 just syntactic sugar?

Ed Avis ed at membled.com
Sat Jun 7 07:12:01 EDT 2003


Sean Legassick <sean at datamage.net> writes:

>>    def f:
>>      print 'hello'
>>    x = f
>>
>>f is an expression, yet it 'contains' a statement.

>f might well be an expression, but surely the 'def f:' is a statement
>with an accompanying suite. It's a kind of assignment statement.

Yes... what we are talking about here, of course, is purely syntax.
Semantically there doesn't seem much difference between defining f
that contains a print statement, and defining an anonymous function
that has the same.  If a clear and simple syntax can be worked out to
let expressions appear in lambda-defined functions, just as they can
in ordinary functions, there doesn't seem to be any other reason to
prohibit it.  I think that the rule of 'anything that fits on one
line' is such a simple rule; just as simple as 'any expression, but
not a statement' and more powerful.

-- 
Ed Avis <ed at membled.com>




More information about the Python-list mailing list