[Python-Dev] any support for a methodcaller HOF?
Eric Nieuwland
eric.nieuwland at xs4all.nl
Sat Feb 4 09:05:37 CET 2006
Nick Coghlan wrote:
> That's like saying "it's not the same because '(x*x def (x)' creates a
> function while '(x*x for x in seq)' creates a generator-iterator".
> Well,
> naturally - if the expression didn't do something different, what
> would be the
> point in having it?
;-)
Naturally. I just wanted to point out it's a beast of another kind, so
like syntax may not be a good idea.
> The parallel I'm trying to draw is at the syntactic level, not the
> semantic.
> I'm quite aware that the semantics will be very different ;)
>
>> Yours is
>>
>> f = lambda x: x*x
>>
>> and it will die by Guido hand...
>
> In the short term, probably. I'm hoping that the progressive
> accumulation of
> workarounds like itemgetter, attrgetter and partial (and Alex's
> suggestion of
> 'methodcaller') and the increasing use of function arguments for
> things like
> sorting and the itertools module will eventually convince Guido that
> deferring
> expressions is a feature that needs to be *fixed* rather than
> discarded entirely.
Then how about nameless function/method definition:
def (x):
... usual body ...
produces an unnamed method object
and
def spam(x):
....
is just
spam = def (x):
...
while our beloved
eggs(lambda x: x*x)
would become
eggs(def(x): return x*x)
--eric
More information about the Python-Dev
mailing list