Hi all-
I was searching through the mail archives for info on coroutines and
stumbled on this:
> Csaba Henk
> Mon, 16 Apr 2007 15:26:44 -0700
> Eg., for Python, I created a generator which yielded the numbers
> from 0
> up to 100,000, and I iterated through it:
>
> def gen():
> for i in xrange(10**5):
> yield i
>
> for i in gen():
> pass
And a Factor version was given in response:
> On 2007-04-16, Chris Double <[EMAIL PROTECTED]> wrote:
> If all you want to test is coroutines, rather than the message passing
> aspects of concurrency, you can use libs/coroutines:
>
> "libs/coroutines" require
> USE: coroutines
> : gen ( -- co ) [ 100000 [ over coyield 2drop ] each f swap
> coyield ] cocreate ;
> : run ( co -- ) f swap coresume [ run ] [ drop ] if ;
>
> [ gen run ] time
>
> This is the equivalent of the Pythonsample you posted. Unfortunately
> continuations don't compile so the test runs interpreted.
The above word "run" won't compile in the current Factor.
I spent some time studying coroutines, but still, what I know would
fit on the head of a pin. I came up with the following:
USE: coroutines
: gen ( -- co ) [ 10000 [ coyield ] each coterminate ] cocreate ;
: run ( co -- ) f over coresume [ run ] [ drop ] if ;
[ gen run ] time
I'm still trying to figure how my solution differs from the previous
one. Also, using recursion, I get a stack overflow if I attempt 10**5
iterations.
Thanks for any insight!
Charles
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk