[stack] Sieve of Eratosthenes

"Ruurd" <[email protected]> Fri, 09 Dec 2011 10:32:19 -0000
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
The Sieve of Eratosthenes has been mentioned earlier in this newsgroup, but I didn't see a solution in Joy. Here is mine:

(*
   popen ( Q -> ) starts a new task. The stdout of the current  
   task is connected to the stdin of the new task.
*)
DEFINE sieve == get dup put [sieve] popen
                [] [get [swap mod] [put] [pop] ifte] while.

DEFINE count == 2 [] [dup put succ] while.

[sieve] popen count.

Of course, there is no such thing as a multi-tasking version of Joy,
but maybe this example shows that it worth the trouble building such
a thing. Is it?