Anonymus functions revisited : tuple actions

Ron_Adam radam2 at
Fri Mar 25 18:00:31 CET 2005

On 24 Mar 2005 22:16:10 -0800, "Kay Schluehr" <kay.schluehr at>

>It's all developed during this discussion. Sometimes I'm a bit
>surprised were it goes.

I enjoy exploring ideas this way. Many times it leads to dead ends or
you just end up with a long way back to where you started, but
sometimes you get a surprise, and almost always a deeper understanding
of the subject. :)

>To make my intention clear for another time, also for George who
>mistrusts these exercises alltogether. I want to derive a syntax and
>semantics for anonymus functions ( called "tuple-actions" ) that are
>generalizations of rules that are already used implicitely within
>Python e.g. tuple-unpacking. This is done by progressive interpretation
>and extension. They are not there by means of an accident, what Guido
>claims about the current lambda which he feels to be sticked onto the

Looking at the syntax of lambda, I think I agree with Guido.

result = lambda *args: expression  

It's works like a function, but is formatted like a for or if
statement.  It should have been something like this.

    result = lambda{ *args: expression}

Another interesting possibility by exploring ideas and concepts.  :)

Using a dictionary instead of ()'s to pass the arguments and
expressions.  This would simplify parsing it, because it could be
handled as an an object instead of having to parse the args and
expression first. 

What if you could:

    x = lambda{ x, y: x+y}  
Hmm comma creates a problem here. so...

    x = lambda{ (x,y): x+Y }

This is more consistent with python syntax and makes more since. the
args are in a tuple as they would be in function.

    x = lambda{ (x,y): x+y } is same as  x = function(x,y): return x+y

Could this work too?:

    x, y, z = lambda{ (x,y): x+y, (x,z):x+z, (x,v):x+v }   

 Short hand for:

    x,y,z = lambda{(x,y):x+y}, lambda{(x,z):x+z, lambda{(x,v):x+v}

For compatibility purposes, You would need to give it a different

    af, afn, ann, lamb, lam, lm, ?

Or just call it what it is.. function{(args):expression}

Then it would be easy to explain, teach, and remember.


More information about the Python-list mailing list