Python is Considered Harmful
Marco Antoniotti
marcoxa at cs.nyu.edu
Mon Oct 27 13:20:47 EST 2003
Bengt Richter wrote:
> On Mon, 27 Oct 2003 11:14:52 GMT, Alex Martelli <aleax at aleax.it> wrote:
>
...
>>No new "directive" needed: it's easy to get "snap-shots" of current
>>values of names into a lambda or other function:
>>
>>map(lambda f: f(1), [lambda x, i=i: x+i for i in range(3)])
>>
>>The "i=i" gets the (outer) value of i at function-definition time and
>>injects it as local variable i in the lambda. You can also rename just
>>as easily (and sometimes it's clearer):
>>
>>map(lambda f: f(1), [lambda x, k=i: x+k for i in range(3)])
>>
>
>
> I think it would be nice if we could inject a value as a local variable
> without being part of the calling signature for the function. E.g., if
> the parameter list had a way to delimit "injected" values so that they
> weren't part of the parameter list per se. E.g., using '|' to separate
> local-variable presets,
>
> map(lambda f: f(1), [lambda x|k=i: x+k for i in range(3)])
Well then, AFAIU, the
lambda x, k = 1: ...
idiom serves to introduce an optional lambda bound variable.
I.e. something that in CL has been there since 1984 and earlier. Your
suggestion is instead along the lines of the &AUX lambda parameter
already present in Common Lisp (another non surprise) since 1984 and before.
But this begs the question. The bottom line is that Python needs to get
proper lambda expressions. The extra "quote" local "unquote" argument
is not what you'd expect.
Cheers
--
Marco Antoniotti
More information about the Python-list
mailing list