a = b = 1 just syntactic sugar?

Ed Avis ed at membled.com
Mon Jun 9 22:38:10 CEST 2003


martin at v.loewis.de (Martin v. =?iso-8859-15?q?L=F6wis?=) writes:

>Looking at your proposal as I interpret it now, it seems you suggest
>allowing the following in a lambda expression:

[list of simple_stmt cases, most of them useless]

>assignment_stmt: supported, but useless

Not so, consider assignment to list and dictionary elements.  (Though
a better way to accomplish this might be to add concise 'set' methods
rather than relying on the somewhat anomalous d[k] = v statement.)

>del_stmt:        supported, but useless

Likewise, not useless for lists and dictionaries.  And again maybe
making a 'del' method would be a better way of addressing the problem.

>To summarize, you can only use print, raise, yield, and exec in a
>meaningful way. Why would I want to have any of these in a lambda
>expression?

IIRC I originally gave three motivating examples:

    lambda x: print 'value', x
    lambda x: assert x > 0
    lambda x: y += x

After thinking about the intended semantics of lambda functions
containing statements, I realize that the third is useless because y
is local to the lambda function.  Although 'y[x] += 5' does have an
effect, and is plausible.

The other two I still think would be useful.

-- 
Ed Avis <ed at membled.com>




More information about the Python-list mailing list