From 5df73e8b14d435bcb5f110ca9e2ae6ab7917e8ee Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 6 Jan 2009 15:49:27 -0800 Subject: make the tutorial programs run again. (the text still needs fixing) add the tutorial programs to the test run. R=rsc DELTA=41 (6 added, 0 deleted, 35 changed) OCL=22174 CL=22174 --- doc/progs/sieve.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'doc/progs/sieve.go') diff --git a/doc/progs/sieve.go b/doc/progs/sieve.go index 1ee60bddf..22e14535e 100644 --- a/doc/progs/sieve.go +++ b/doc/progs/sieve.go @@ -5,7 +5,7 @@ package main // Send the sequence 2, 3, 4, ... to channel 'ch'. -func Generate(ch *chan int) { +func Generate(ch chan int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. } @@ -13,9 +13,9 @@ func Generate(ch *chan int) { // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. -func Filter(in, out *chan int, prime int) { +func Filter(in, out chan int, prime int) { for { - i := <-in // Receive value of new variable 'i' from 'in'. + i := <-in; // Receive value of new variable 'i' from 'in'. if i % prime != 0 { out <- i // Send 'i' to channel 'out'. } @@ -24,12 +24,12 @@ func Filter(in, out *chan int, prime int) { // The prime sieve: Daisy-chain Filter processes together. func main() { - ch := new(chan int); // Create a new channel. + ch := make(chan int); // Create a new channel. go Generate(ch); // Start Generate() as a goroutine. for { prime := <-ch; print(prime, "\n"); - ch1 := new(chan int); + ch1 := make(chan int); go Filter(ch, ch1, prime); ch = ch1 } -- cgit v1.2.3