github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/hellogophers/sieve.newsqueak (about)

     1  counter:=prog(end: int, c: chan of int)
     2  {
     3  	i:int;
     4  	for(i=2; i<end; i++)
     5  		c<-=i;
     6  };
     7  
     8  filter:=prog(prime: int, listen: chan of int, send: chan of int)
     9  {
    10  	i:int;
    11  	for(;;)
    12  		if((i=<-listen)%prime)
    13  			send<-=i;
    14  };
    15  # BREAK OMIT
    16  sieve:=prog(c: chan of int)
    17  {
    18  	for(;;){
    19  		prime:=<-c;
    20  		print(prime, " ");
    21  		newc:=mk(chan of int);
    22  		begin filter(prime, c, newc);
    23  		c=newc;
    24  	}
    25  };
    26  
    27  count:=mk(chan of int);
    28  
    29  begin counter(10000, count);
    30  begin sieve(count);
    31  "";