[Python-Dev] accumulator display syntax
Phillip J. Eby
pje at telecommunity.com
Fri Oct 17 16:38:00 EDT 2003
At 03:20 PM 10/17/03 -0500, Skip Montanaro wrote:
> * functions
> * unbound methods
> * bound methods
> * generator functions
> * iterators (currently invisible via syntax, but created by calling a
> generator function?)
> * instances magically callable via __call__
The last item on the list encompasses at least the first three. But you
also left out __init__ and __new__, which are really ClassType.__call__ or
type.__call__, though. :)
To me (and the interpreter, actually), there's just tp_call, tp_iter, and
tp_iternext (or whatever their actual names are). Callability,
iterability, and iterator-next. Many kinds of objects may have these
aspects, just as many kinds of objects may be addable with '+'.
Of the things you mention, however, most don't actually have different
syntax for creating them, and some are even the same object type (e.g.
unbound and bound methods). And the syntax for *using* them is always
uniform: () always calls an object, for ... in ... creates an iterator from
an iterable, .next() goes to the next item.
>and now this new (rather limited) syntax for creating iterators.
Actually, as now being discussed, list comprehensions would be a special
case of an iterator expression.
>I am beginning to find it all a bit confusing and unsettling.
Ironically, with iterator comprehension in place, a list comprehension
would now look like a list containing an iterator, which I agree might be
confusing. Too bad we didn't do iterator comps first, or list(itercomp)
would be the idiomatic way to make a listcomp.
That's really the only confusing bit I see about itercomps... that you
have to be careful where you put your parentheses, in order to make your
intentions clear in some contexts. However, that's true for many kinds of
expressions even now.
More information about the Python-Dev