[Python-Dev] any support for a methodcaller HOF? (original) (raw)

Ben.Young at risk.sungard.com Ben.Young at risk.sungard.com
Fri Feb 3 11:15:54 CET 2006


Michael Hudson wrote on 03/02/2006 09:36:30:

Hmm. >>> funcTakingCallback(lamda x:x.method(zip, zop)) >>> funcTakingCallback(methodcaller("method", zip, zop)) I'm not sure which of these is clearer really. Are lambdas so bad? (FWIW, I haven't internalized itemgetter/attrgetter yet and still tend to use lambdas instead those too). A class I wrote (and lost) ages ago was a "placeholder" class, so if 'X' was an instance of this class, "X + 1" was roughly equivalent to "lambda x:x+1" and "X.method(zip, zop)" was roughly equivalent to your "methodcaller("method", zip, zop)". I threw it away when listcomps got implemented. Not sure why I mention it now, something about your post made me think of it...

The C++ library Boost makes use of this method, but has a number of "placeholder" variables _1, _2, _3 ... _9 which can be combined to form expressions. e.g _1 + _2 is the same as lambda x,y: x+y so maybe there could be a lambda module that exposes placeholders like this. Pythons ones will be better that the C++ ones because we would be able to delay function calls as above with a much nicer syntax than the C++ versions. E.g

_1.method(_2+_3) !

Cheers, Ben

Cheers, mwh

-- If you give someone Fortran, he has Fortran. If you give someone Lisp, he has any language he pleases. -- Guy L. Steele Jr, quoted by David Rush in comp.lang.scheme.scsh


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python- dev/python%40theyoungfamily.co.uk



More information about the Python-Dev mailing list