Fake threads (was [Python-Dev] ActiveState & fork & Perl)
Tim Peters
tim_one@email.msn.com
Tue, 13 Jul 1999 23:56:20 -0400
[Vladimir Marangozov]
> Yes. I'm trying to understand the following:
>
> 1. What does a generator generate?
Any sequence of objects: the lines in a file, the digits of pi, a postorder
traversal of the nodes of a binary tree, the files in a directory, the
machines on a LAN, the critical bugs filed before 3/1/1995, the set of
builtin types, all possible ways of matching a regexp to a string, the
5-card poker hands beating a pair of deuces, ... anything!
Icon uses the word "generators", and it's derived from that language's
ubiquitous use of the beasts to generate paths in a backtracking search
space.
In OO languages it may be better to name them "iterators", after the closest
common OO concept. The CLU language had full-blown (semi-coroutine, like
Icon generators) iterators 20 years ago, and the idea was copied &
reinvented by many later languages. Sather is probably the best known of
those, and also calls them iterators.
> 2. Clearly, what's the difference between a generator and a thread?
If you can clearly explain what "a thread" is, I can clearly explain the
similarities and differences. Well? I'm holding my breath here <wink>.
Generators/iterators are simpler than threads, whether looked at from a
user's viewpoint or an implementor's. Their semantics are synchronous and
deterministic.
Python's for/__getitem__ protocol *is* an iterator protocol already, but if
I ask you which is the 378th 5-card poker hand beating a pair of deuces, and
ask you a new question like that every hour, you may start to suspect there
may be a better way to *approach* coding enumerations in general <wink>.
then-again-there-may-not-be-ly y'rs - tim