Anonymus functions revisited : tuple actions

Kay Schluehr kayschluehr at gmx.de
Wed Mar 23 06:21:30 CET 2005

```Hi all,

I think my proposal was more in mind of Rons modified exec than
Pythons lambda.

When George proposed his unpacking behavoir for list-comps as a pack of
suggar:

1. [x*y-z for (x,y,z=0) in (1,2,3), (4,5), (6,7,8)]

I interpreted it in a subsequent posting in lambda fashion:

2. [(lambda x,y,z=0:x*y-z)(*v) for v in (1,2,3), (4,5), (6,7,8)]

which would be equivalent, if Georges syntax became standard Python.

This motivates a fresh view on tuples as unpacking actions on other tuples
which could be generalized to anonymus functions which are quite similar
to Pythons lambda but are NOT the Python lambda because of different
scoping rules
which was addressed lately by Rons and Georges postings in this thread.

>>> [x*y-z for (x,y,z) in (1,2,3),(4,5,6)]
[-1,14]
>>>> x,y
(4,5)

x and y are bound variables that are visible outside the list-comp !

So it would be with (x,y,z) -> (x,y,z) when it is applied to any tuple
(a,b,c) with 3 elements. It does not return (a,b,c) but (x,y,z) with
x = a, y = b, z = c. This is the reason why it is simple to chain
tuple-actions.

In 1. we have actually two different tuple actions:

f = (x,y,z=0) -> (x,y,z)
g = (x,y,z)   -> x*y-z

which is chainable by g o f.

If we expand the notion of tuple-action in the list-comp 1. we get

[(x,y,z)->x*y-z for (x,y,z=0)->(x,y,z) in (1,2,3), (4,5), (6,7,8)]

which is still a short form of the explicit

[((x,y,z)->x*y-z)(x,y,z) for (x,y,z=0)->(x,y,z) in (1,2,3), (4,5), (6,7,8)].

There is still no such thing as a free/unbound variable as in real
lambda calculus
that can be bound by another lambda. Tuple actions would obviously sweep
off this
misguided association - o.k not so for Pythonistas ;)

Maybe Guidos aversion against FP is bit misguided too because it is
actually in
the language but hidden as special rules.

Regards Kay

```