[Python-Dev] accumulator display syntax

Phillip J. Eby pje at telecommunity.com
Fri Oct 17 13:53:56 EDT 2003


At 06:52 PM 10/17/03 +0200, Alex Martelli wrote:
>On Friday 17 October 2003 06:03 pm, Phillip J. Eby wrote:
> > Yes, what you propose is certainly *possible*.  But again, if you really
> > needed an iterator as an index, you can right now do:
> >
> > sum[ [x*x for x in blaap] ]
>
>Actually, I need to use parentheses on the outside and brackets only
>on the inside -- I assume that's what you meant, of course.

No, I meant what I said, which was that if you "really needed an iterator 
as an *index*" (emphasis added).  I suppose I technically should have said, 
if you really want to provide an *iterable*, since a list is not an 
iterator.  But I figured you'd know what I meant.  :)


>I agree it's clearer -- a tad less flexible, as you don't get to do separately
>     selector = Top(10)
>and then somewhere else
>     selector[...]
>but "oh well", and anyway the issue would be overcome if we had currying
>(we could be said to have it, but -- I assume you'd consider
>     selector = Top.__get__(10)
>some kind of abuse, and besides, this 'currying' isn't very general).

Hmmm...  that's a hideously sick hack to perform currying...  but I *like* 
it.  :) Not to use inline, of course, I'd wrap it in a 'curry' 
function.  But what a lovely way to *implement* it, under the hood.  Of 
course, I'd actually use 'new.instancemethod', since it would do the same 
thing for any callable, not just functions.  But I never thought of using 
method objects for providing a currying operation (in the general sense) 
before, even though I've sometimes used as part of a framework to pass 
along extra operators to chained functions.




More information about the Python-Dev mailing list