1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:04:41 -07:00

delete incorrect, dreg example of select on type

R=gri,rsc
DELTA=48  (28 added, 11 deleted, 9 changed)
OCL=26630
CL=26701
This commit is contained in:
Rob Pike 2009-03-24 17:40:47 -07:00
parent a805e54a38
commit 94b67eb8d8

View File

@ -1121,6 +1121,7 @@ value is made using the built-in function <code>make</code>,
which takes the channel type and an optional capacity as arguments: which takes the channel type and an optional capacity as arguments:
</p> </p>
<pre> <pre>
make(chan int, 100) make(chan int, 100)
</pre> </pre>
@ -1132,6 +1133,15 @@ buffer is not full, sends can succeed without blocking. If the capacity is zero
or absent, the communication succeeds only when both a sender and receiver are ready. or absent, the communication succeeds only when both a sender and receiver are ready.
</p> </p>
<p>
For a channel <code>c</code>, the predefined function <code>close(c)</code>
marks the channel as unable to accept more
values through a send operation. After any previously
sent values have been received, receives will return
the zero value for the channel's type. After at least one such zero value has been
received, <code>closed(c)</code> returns true.
</p>
<h2>General properties of types and values</h2> <h2>General properties of types and values</h2>
<p> <p>
@ -3258,9 +3268,15 @@ in the type guard.
TypeSwitchStat = "switch" [ [ SimpleStat ] ";" ] TypeSwitchGuard "{" { TypeCaseClause } "}" . TypeSwitchStat = "switch" [ [ SimpleStat ] ";" ] TypeSwitchGuard "{" { TypeCaseClause } "}" .
TypeSwitchGuard = identifier ":=" Expression "." "(" "type" ")" . TypeSwitchGuard = identifier ":=" Expression "." "(" "type" ")" .
TypeCaseClause = TypeSwitchCase ":" [ StatementList ] . TypeCaseClause = TypeSwitchCase ":" [ StatementList ] .
TypeSwitchCase = "case" type | "default" . TypeSwitchCase = "case" ( type | "nil" ) | "default" .
</pre> </pre>
<p>
If the interface value equals <code>nil</code>,
only an explict <code>nil</code> case or "default"
case will execute.
</p>
<p> <p>
Given a function <code>f</code> Given a function <code>f</code>
that returns a value of interface type, that returns a value of interface type,
@ -3269,6 +3285,8 @@ the following type switch:
<pre> <pre>
switch i := f().(type) { switch i := f().(type) {
case nil:
printString("f() returns nil");
case int: case int:
printInt(i); // i is an int printInt(i); // i is an int
case float: case float:
@ -3286,7 +3304,9 @@ could be rewritten:
<pre> <pre>
v := f(); v := f();
if i, is_int := v.(int); is_int { if v == nil {
printString("f() returns nil");
} else if i, is_int := v.(int); is_int {
printInt(i); // i is an int printInt(i); // i is an int
} else if i, is_float := v.(float); is_float { } else if i, is_float := v.(float); is_float {
printFloat(i); // i is a float printFloat(i); // i is a float
@ -3379,9 +3399,10 @@ RangeClause = IdentifierList ( "=" | ":=" ) "range" Expression .
<p> <p>
The type of the right-hand expression in the "range" clause must be an array, The type of the right-hand expression in the "range" clause must be an array,
slice or map, or a pointer to an array, slice or map. slice or map, or a pointer to an array, slice or map;
The slice or map must not be <code>nil</code> (TODO: really?). or it may be a channel.
The identifier list must contain one or two identifiers denoting the If it is an array, slice or map,
the identifier list must contain one or two identifiers denoting the
iteration variables. On each iteration, iteration variables. On each iteration,
the first variable is set to the array or slice index or the first variable is set to the array or slice index or
map key, and the second variable, if present, is set to the corresponding map key, and the second variable, if present, is set to the corresponding
@ -3391,6 +3412,11 @@ and element, or of the map key and value respectively,
must be assignment compatible to the iteration variables. must be assignment compatible to the iteration variables.
</p> </p>
<p> <p>
For channels, the identifier list must contain one identifier.
The iteration recieves values sent on the channel until the channel is closed;
it does not process the zero value sent before the channel is closed.
</p>
<p>
The iteration variables may be declared by the "range" clause (":="), in which The iteration variables may be declared by the "range" clause (":="), in which
case their scope ends at the end of the "for" statement (§Declarations and case their scope ends at the end of the "for" statement (§Declarations and
scope rules). In this case their types are set to scope rules). In this case their types are set to
@ -3516,16 +3542,6 @@ for { // send random sequence of bits to c
case c &lt;- 1: case c &lt;- 1:
} }
} }
var ca chan interface {};
var i int;
var f float;
select {
case i = &lt;-ca:
print("received int ", i, " from ca\n");
case f = &lt;-ca:
print("received float ", f, " from ca\n");
}
</pre> </pre>
<font color=red> <font color=red>
@ -3726,6 +3742,8 @@ for i := 0; i &lt;= 3; i++ {
<h2>Predeclared functions</h2> <h2>Predeclared functions</h2>
<ul> <ul>
<li>cap <li>cap
<li>close
<li>closed
<li>len <li>len
<li>make <li>make
<li>new <li>new
@ -4062,11 +4080,10 @@ func generate(ch chan <- int) {
// Copy the values from channel 'in' to channel 'out', // Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'. // removing those divisible by 'prime'.
func filter(in chan <- int, out <-chan int, prime int) { func filter(src chan <- int, dst <-chan int, prime int) {
for { for i := range src { // Loop over values received from 'src'.
i := <-in; // Receive value of new variable 'i' from 'in'.
if i % prime != 0 { if i % prime != 0 {
out <- i // Send 'i' to channel 'out'. dst <- i // Send 'i' to channel 'dst'.
} }
} }
} }