[Stackless] Stackless support generator functions?
Aaron Watters
aaron at reportlab.com
Thu Sep 26 22:23:21 CEST 2002
whoops. I meant to cc the list on this
Aaron Watters wrote:
> You are right. Thanks!
>
> I guess I chose a bad example, but I think my general point
> still stands. Your correction to my example is well taken,
> however
>
> Ok, how about this
>
> def inorderMap(tree, function):
> (value, children) = tree
> function(value)
> for c in children:
> inorderMap(c, function)
>
> You can do this
>
> def function1(x):
> print x
>
> def function2(x):
> channel.send(x)
>
> def function3(x):
> List.append(x)
>
> inorderMap(tree, function1); inorderMap(tree, function2);
> inorderMap(tree, function3)
>
> but this does NOT work (no?)
>
> def function4(x):
> yield x
>
> Basically in my view the "yield" mechanism and procedural
> abstraction don't really mix well.
>
> As always corrections are always appreciated, thanks.
>
> -- Aaron Watters
>
> Richard Cooper wrote:
>
>> 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
>>
>
>
_______________________________________________
Stackless mailing list
Stackless at www.tismer.com
http://www.tismer.com/mailman/listinfo/stackless
More information about the Stackless
mailing list