Iterators & generators (RE: Real Problems with Python)

Andrew Cooke andrew at andrewcooke.free-online.co.uk
Tue Feb 15 08:48:01 EST 2000


In article <000001bf768e$48e40580$45a0143f at tim>,
  "Tim Peters" <tim_one at email.msn.com> wrote:
>    def traverse_post(self):
>        for child in self.left, self.right:
>            if child is not None:
>                suspend child.traverse_post()
>        suspend self.data

That finally hammered home to me just what continuations are all about.
Does anyone have something similarly elegant that shows a coroutine?
I've just had a look at the stackless python documentation and
coroutines seem to be described as something coming out of a single
detailed example.  Is there a simpler definition?  (I did look back
through some posts on Deja, but there was nothing recent that seemed to
explain what a coroutine actually is - sorry if I've missed something
obvious).

Also, comp.lang.lisp is currently dissing continuations.  Would that be
because the alternative is to pass the code that will process the node
into the iterator as a (first class) function?  Obviously, in this case,
yes, but is that true in general (are there examples where continuations
or coroutines make something possible that really is tricky to do in
other ways)?

Thanks,
Andrew


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list