[Python-Dev] Intended to work? (lambda x,y:map(eval, ["x", "y"]))(2,3)

Christian Tismer tismer@tismer.com
Thu, 25 Jan 2001 14:22:32 +0200

In a function like this:

def f(x):
  return eval("x")

, eval uses the local function namespace, and the above works.
This is according to chapter 2.3 of the Python library ref.

Now on my problem: When eval() is used with map, the same
mechanism takes place:

def f(x):
  return map(eval,["x"])

It works the same as the above, because map is a builtin function
that does not modify the frame chain, so eval finds the local
Not so with Stackless Python (at the moment), since Stackless map
assigns an own frame to map without passing the correct namespaces
to it. (Reported by Bernd Rinn)

Question: Is this by chance, or is eval() *meant* to function with
the local namespace, even if it is executed in the context of
a function like map() ?

The description of map() does not state whether it has to pass
its surrounding namespace to the mapped function, and if one
simulates map() by writing one's own python implementation,
it will fail exactly like Stackless does today. The same
applies to apply().

I think I should fix Stackless here, anyway?

ciao - chris

Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com