[Stackless] Stackless support generator functions?

Richard Cooper Richard.Cooper at aprsmartlogik.com
Thu Sep 26 17:37:02 CEST 2002


Actually a yield version of your preorderToChannel function wouldn't be much
more complicated. Yes, you can only yield up one level but you can quite
easily yield what was just yielded to you.

Of the top of my head it would look like this (Untested):

def preorderGenerator(tree):
    (node, children) = tree
    yield node
    for child in children:
        for x in preorderGenerator(child):
            yield x

Rich

--
Richard Cooper

-----Original Message-----
From: Aaron Watters [mailto:aaron at reportlab.com]
Sent: 26 September 2002 15:14
To: Robert Oschler
Cc: Stackless at tismer.com
Subject: Re: [Stackless] Stackless support generator functions?


I don't know the answer (I assume so), but I do know that channels provide
far more general functionality.  The yeild thing only goes one level deep
into a function call, whereas a channel can pass values from anywhere inside
a computation.

For example you could "linearize" a tree something like this

def preorderToChannel(tree, channel):
      (node, children) = tree
      channel.send(node)
      for child in children:
             preorderToChannel(child, channel)

...then launch preorderToChannel(tree, channel) in its own tasklet.

As I understand it implementing a "preorder generator" using
the "yeild" construct would be much more complicated, unless
you cheated and stashed the result in a list or something first.

Please correct me if I'm wrong...

   -- Aaron Watters

Robert Oschler wrote:

Does Stackless support Python 2.2 generator functions?

thx
_______________________________________________
Stackless mailing list
Stackless at www.tismer.com
http://www.tismer.com/mailman/listinfo/stackless



More information about the Stackless mailing list