[Python-Dev] Re: Single- vs. Multi-pass iterability

Alex Martelli aleax@aleax.it
Fri, 19 Jul 2002 19:35:53 +0200


On Friday 19 July 2002 07:23 pm, Guido van Rossum wrote:
> > Do you intend to have a test for "is this an iterator" at all?
>
> Not right now, see the rest of my email.  The best you can do is check
> for a next method and hope for the best.
>
> > If LBYL is bad, what is introspection good for?
>
> Ask Alex.

Introspection is good when you need to dispatch in a way that is
not supported by the language you're using.  In Python (and most
other languages), this mostly mean multiple dispatch -- you don't
get it from the language, therefore, on the non-frequent occasions
when you NEED it, you have to kludge it up.  Very similar to
multiple inheritance in languages that don't support THAT, really.

(Particularly in how people who've never used multiple X don't
really understand that it buys you anything -- try interesting a
dyed-in-the-wool Smalltalker in multiple inheritance, or anybody
*but* a CLOS-head or Dylan-head in multiple dispatch...:-).

Other aspects of introspection help you implement other primitives
lacking in the language.  E.g. "make another like myself but not
initialized" can be self.__class__.__new__(self.__class__) -- not
the most elegant expression, but, hey, I've seen worse (such as
NOT being able to express it at all, in languages lacking the
needed ability to introspect:-).

Looking at *ANOTHER* object this way isn't really INTROspection,
btw -- it's EXTRAspection, by the Latin roots of these words:-).



Alex