home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / interpre / proxy / sieve.prx < prev    next >
Text File  |  1994-03-03  |  663b  |  21 lines

  1. eos="eos";
  2. ch1=channel();
  3. ch2=channel();
  4. task gen(out,n;i) {
  5.  i=2;
  6.  while(i<=n) {
  7.    out!i;
  8.    i=i+1;}
  9.  out!eos;};
  10. task sink(inp;x) {inp?x;while(x!=eos) {print x;inp?x;}};
  11. task sieve(inp,out;x,y,succ) {inp?x;
  12.                               if(x==eos) {out!eos;skip;}
  13.                               succ = channel();
  14.                               start sieve(succ,out);
  15.                               while(true)
  16.                                {inp?y;
  17.                                 if(y==eos) {out!x;succ!eos;skip;}
  18.                                 if(y%x!=0) succ!y;}};
  19. task main(n) {start gen(ch1,n);start sieve(ch1,ch2);start sink(ch2);};
  20. end
  21.