From e1e7619f019cd01386172536ba7caab9de7a51a3 Mon Sep 17 00:00:00 2001
From: Robert Griesemer \377
and \xFF
represent
a single byte of value 0xFF
=255, while ÿ
,
\u00FF
, \U000000FF
and \xc3\xbf
represent
-the two bytes 0xc3 0xbf
of the UTF-8 encoding of character
+the two bytes 0xc3
0xbf
of the UTF-8 encoding of character
U+00FF.
-chan T // can be used to send and receive values of type T -chan <- float // can only be used to send floats +chan T // can be used to send and receive values of type T +chan<- float // can only be used to send floats <-chan int // can only be used to receive ints@@ -2796,7 +2796,7 @@ a channel and a value (expression):
-ch <- 3 +ch <- 3
@@ -2817,10 +2817,10 @@ These two examples are equivalent:
-ok := ch <- 3; +ok := ch <- 3; if ok { print("sent") } else { print("not sent") } -if ch <- 3 { print("sent") } else { print("not sent") } +if ch <- 3 { print("sent") } else { print("not sent") }
@@ -2836,7 +2836,7 @@ is the element type of the channel.
-<-ch +<-ch
@@ -2847,10 +2847,10 @@ discarded.
-v1 := <-ch -v2 = <-ch -f(<-ch) -<-strobe // wait until clock pulse +v1 := <-ch +v2 = <-ch +f(<-ch) +<-strobe // wait until clock pulse
@@ -2858,9 +2858,9 @@ If a receive expression is used in an assignment or initialization of the form
-x, ok = <-ch -x, ok := <-ch -var x, ok = <-ch +x, ok = <-ch +x, ok := <-ch +var x, ok = <-ch
@@ -3079,12 +3079,12 @@ order. Otherwise, the order of evaluation is unspecified. For example, in the assignment
-y[f()], ok = g(h(), i() + x[j()], <-c), k() +y[f()], ok = g(h(), i() + x[j()], <-c), k()
the function calls and communication happen in the order
f()
, h()
, i()
, j()
,
-<-c
, g()
, and k()
.
+<-c
, g()
, and k()
.
However, the order of those events compared to the evaluation
and indexing of x
and the evaluation
of y
is not specified.
@@ -3166,7 +3166,7 @@ ExpressionStmt = Expression .
f(x+y) -<-ch +<-ch@@ -3212,7 +3212,7 @@ or the blank identifier. x = 1 *p = f() a[i] = 23 -k = <-ch +k = <-ch
@@ -3648,7 +3648,7 @@ for the invoked function to complete.
go Server() -go func(ch chan <- bool) { for { sleep(10); ch <- true; }} (c) +go func(ch chan<- bool) { for { sleep(10); ch <- true; }} (c)@@ -4252,37 +4252,37 @@ package main import "fmt" // 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'. + ch <- i; // Send 'i' to channel 'ch'. } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. -func filter(src chan <- int, dst <-chan int, prime int) { - for i := range src { // Loop over values received from 'src'. - if i % prime != 0 { - dst <- i // Send 'i' to channel 'dst'. +func filter(src <-chan int, dst chan<- int, prime int) { + for i := range src { // Loop over values received from 'src'. + if i%prime != 0 { + dst <- i; // Send 'i' to channel 'dst'. } } } // The prime sieve: Daisy-chain filter processes together. func sieve() { - ch := make(chan int); // Create a new channel. - go generate(ch); // Start generate() as a subprocess. + ch := make(chan int); // Create a new channel. + go generate(ch); // Start generate() as a subprocess. for { - prime := <-ch; + prime := <-ch; fmt.Print(prime, "\n"); ch1 := make(chan int); go filter(ch, ch1, prime); - ch = ch1 + ch = ch1; } } func main() { - sieve() + sieve(); } -- 2.48.1