summaryrefslogtreecommitdiff
path: root/doc/progs/sieve.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-01-06 15:49:27 -0800
committerRob Pike <r@golang.org>2009-01-06 15:49:27 -0800
commit5df73e8b14d435bcb5f110ca9e2ae6ab7917e8ee (patch)
treebaa8a65017491726042d244d68061a3599ab7741 /doc/progs/sieve.go
parent92743b1fbff6b14864c4ffd200042e5a65a2b1c1 (diff)
downloadgolang-5df73e8b14d435bcb5f110ca9e2ae6ab7917e8ee.tar.gz
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
Diffstat (limited to 'doc/progs/sieve.go')
-rw-r--r--doc/progs/sieve.go10
1 files changed, 5 insertions, 5 deletions
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
}