From: Rob Pike Date: Wed, 16 Jul 2008 03:52:07 +0000 (-0700) Subject: channel tests with new syntax X-Git-Tag: weekly.2009-11-06~3484 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=33101926f9196bcf872ab5560543f30660d17e2d;p=gostls13.git channel tests with new syntax SVN=127436 --- diff --git a/test/chan/fifo.go b/test/chan/fifo.go index 114e7d0876..6112b3cd6f 100644 --- a/test/chan/fifo.go +++ b/test/chan/fifo.go @@ -13,22 +13,22 @@ const N = 10 func AsynchFifo() { ch := new(chan int, N); for i := 0; i < N; i++ { - >ch = i + ch -< i } for i := 0; i < N; i++ { - if int) { - BUG := out = 1; + out -< 1 } // thread together a daisy chain to read the elements in sequence @@ -41,9 +41,9 @@ func SynchFifo() { go Chain(ch, i, in, out); in = out; } - >start = 0; + start -< 0; for i := 0; i < N; i++ { - >ch = i + ch -< i } } diff --git a/test/chan/sieve.go b/test/chan/sieve.go index 8644247e76..c1cf690a26 100644 --- a/test/chan/sieve.go +++ b/test/chan/sieve.go @@ -10,30 +10,30 @@ package main // Send the sequence 2, 3, 4, ... to channel 'ch'. -func Generate(ch *chan> int) { - for i := 2; i<100; i++ { - >ch = i // Send 'i' to channel 'ch'. +func Generate(ch *chan-< int) { + for i := 2; ; i++ { + ch -< i // Send 'i' to channel 'ch'. } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. -func Filter(in *chan< int, out *chan> int, prime int) { +func Filter(in *chan<- int, out *chan-< int, prime int) { for { - i := out = i // Send 'i' to channel 'out'. + out -< i // Send 'i' to channel 'out'. } } } // The prime sieve: Daisy-chain Filter processes together. -func Sieve(primes *chan> int) { - ch := new(chan int); // Create a new channel. - go Generate(ch); // Start Generate() as a subprocess. +func Sieve() { + ch := new(chan int); // Create a new channel. + go Generate(ch); // Start Generate() as a subprocess. for { - prime := primes = prime; + prime := <-ch; + print prime, "\n"; ch1 := new(chan int); go Filter(ch, ch1, prime); ch = ch1 @@ -43,30 +43,30 @@ func Sieve(primes *chan> int) { func main() { primes := new(chan int); go Sieve(primes); - if int) { - for i := 2; ; i++ { - >ch = i // Send 'i' to channel 'ch'. - } +func Generate(ch *chan-< int) { + for i := 2; ; i++ { + ch -< i // Send 'i' to channel 'ch'. + } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. -func Filter(in *chan< int, out *chan> int, prime int) { - for { - i := out = i // Send 'i' to channel 'out'. - } - } +func Filter(in *chan<- int, out *chan-< int, prime int) { + for { + i := <-in // Receive value of new variable 'i' from 'in'. + if i % prime != 0 { + out -< i // Send 'i' to channel 'out'. + } + } } // The prime sieve: Daisy-chain Filter processes together. func Sieve() { - ch := new(chan int); // Create a new channel. - go Generate(ch); // Start Generate() as a subprocess. - for { - prime :=