[Python-Dev] Let's just *keep* lambda
brett at python.org
Tue Feb 7 23:05:32 CET 2006
On 2/7/06, Michael Urman <murman at gmail.com> wrote:
> On 2/6/06, Brett Cannon <brett at python.org> wrote:
> > And I think that a deferred object would help with one of
> > lambda's biggest uses and made its loss totally reasonable.
> The ambiguity inherent from the perspective of a deferred object makes
> a general one impractical. Both map(Deferred().attribute, seq) and
> map(Deferred().method(arg), seq) look the same - how does the object
> know that the first case it should return the attribute of the first
> element of seq when called, but in the second it should wait for the
> next call when it will call method(arg) on the first element of seq?
Magic. =) Honestly, I don't know, but I bet there is some evil,
black magic way to pull it off. Otherwise, worst case, Deferred takes
an argument that flags that it has a method being called on it for it
to defer against and not to treat it as an attribute access only. And
that is within reason in terms of interace requirement for the object,
in my opinion.
> Since there's also no way to spell "lambda y: foo(x, y, z)" on a
> simple deferred object, it's strictly less powerful. If the current
> Python lambda's functionality is desired, there is no better pythonic
> way to spell it. There are plenty of new syntactic options that help
> highlight its expression nature, but are they worth the change?
I never claimed that a deferred object would replace all uses of
lambda, just that it would make it reasonable. For the above
suggestion I would go to a named function. Or, if the argument was on
the end or everything named, use functional.partial().
More information about the Python-Dev