[Python-Dev] Re: "groupby" iterator
Phillip J. Eby
pje at telecommunity.com
Wed Dec 3 12:29:46 EST 2003
At 07:04 PM 12/3/03 +0200, Christos Georgiou wrote:
>A minor correction: the Voodoo approach handles fine method calls by
>defining a __call__ method in the Voodoo class;
__call__ is needed for the resulting object to be callable.
>it can't handle
>*function* calls in an elegant way:
>lambda x: x.startswith("text")
>This works fine as:
Voodoo().startswith("text") is equivalent to (lambda x:
x.startswith)("text"), which is not the same thing.
>lambda x: math.sin(x)
>This needs gross syntax, the following does not work:
That too, but also method calls. Basically, once you get past really
simple expressions, the whole thing collapses under its own weight.
Ironically, it would be easy to do this with generic functions, since one
would simply define a methods for the case 'math.sin(Voodoo)' that returns
lambda x: math.sin(x).
(Hm. This gives me an entirely unrelated idea about how to unify object
methods and generic functions in Python using "curried
generics". Interesting. And the Voodoo() aka 'arg()' concept could be
applied to predicate dispatching as well.)
More information about the Python-Dev