diff options
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r-- | doc/go_spec.html | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index 85dfc44bd..f8fe5974a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ <!-- title The Go Programming Language Specification --> -<!-- subtitle Version of March 3, 2011 --> +<!-- subtitle Version of Apr 5, 2011 --> <!-- TODO @@ -1235,8 +1235,11 @@ receiver are ready. </p> <p> -A channel may be closed and tested for closure with the built-in functions -<a href="#Close_and_closed"><code>close</code> and <code>closed</code></a>. +A channel may be closed with the built-in function +<a href="#Close"><code>close</code></a>; the +multi-valued assignment form of the +<a href="#Receive_operator">receive operator</a> +tests whether a channel has been closed. </p> <h2 id="Properties_of_types_and_values">Properties of types and values</h2> @@ -1469,6 +1472,7 @@ declarations. Labels are declared by <a href="#Labeled_statements">labeled statements</a> and are used in the <code>break</code>, <code>continue</code>, and <code>goto</code> statements (§<a href="#Break_statements">Break statements</a>, §<a href="#Continue_statements">Continue statements</a>, §<a href="#Goto_statements">Goto statements</a>). +It is illegal to define a label that is never used. In contrast to other identifiers, labels are not block scoped and do not conflict with identifiers that are not labels. The scope of a label is the body of the function in which it is declared and excludes @@ -1496,7 +1500,7 @@ Zero value: nil Functions: - append cap close closed complex copy imag len + append cap close complex copy imag len make new panic print println real recover </pre> @@ -3029,9 +3033,6 @@ f(<-ch) <-strobe // wait until clock pulse and discard received value </pre> -<!-- - TODO(rsc): Add after a release or two without any x,ok := <-c. - <p> A receive expression used in an assignment or initialization of the form </p> @@ -3049,7 +3050,6 @@ the received value was sent on the channel (<code>true</code>) or is a <a href="#The_zero_value">zero value</a> returned because the channel is closed and empty (<code>false</code>). </p> ---> <p> Receiving from a <code>nil</code> channel causes a @@ -4009,9 +4009,8 @@ iteration values for each entry will be produced at most once. <li> For channels, the iteration values produced are the successive values sent on -the channel until the channel is closed; it does not produce the zero value sent -before the channel is closed -(§<a href="#Close_and_closed"><code>close</code> and <code>closed</code></a>). +the channel until the channel is closed +(§<a href="#Close"><code>close</code>). </li> </ol> @@ -4086,12 +4085,9 @@ cases all referring to communication operations. SelectStmt = "select" "{" { CommClause } "}" . CommClause = CommCase ":" { Statement ";" } . CommCase = "case" ( SendStmt | RecvStmt ) | "default" . -RecvStmt = [ Expression ( "=" | ":=" ) ] RecvExpr . +RecvStmt = [ Expression [ "," Expression ] ( "=" | ":=" ) ] RecvExpr . RecvExpr = Expression . </pre> -<!-- TODO(rsc): -RecvStmt = [ Expression [ "," Expression ] ( "=" | ":=" ) ] RecvExpr . ---> <p> RecvExpr must be a <a href="#Receive_operator">receive operation</a>. @@ -4122,27 +4118,24 @@ in the "select" statement. If multiple cases can proceed, a pseudo-random fair choice is made to decide which single communication will execute. <p> -<!-- TODO(rsc): s/variable/& or &s/ --> -The receive case may declare a new variable using a +The receive case may declare one or two new variables using a <a href="#Short_variable_declarations">short variable declaration</a>. </p> <pre> -var c, c1, c2 chan int +var c, c1, c2, c3 chan int var i1, i2 int select { case i1 = <-c1: print("received ", i1, " from c1\n") case c2 <- i2: print("sent ", i2, " to c2\n") -<!-- TODO(rsc): add , c3 to channel list above too case i3, ok := <-c3: if ok { print("received ", i3, " from c3\n") } else { print("c3 is closed\n") } ---> default: print("no communication\n") } @@ -4212,7 +4205,7 @@ func complex_f2() (re float64, im float64) { </pre> </li> <li>The expression list may be empty if the function's result - type specifies names for its result parameters (§<a href="#Function_Types">Function Types</a>). + type specifies names for its result parameters (§<a href="#Function_types">Function Types</a>). The result parameters act as ordinary local variables and the function may assign values to them as necessary. The "return" statement returns the values of these variables. @@ -4222,6 +4215,11 @@ func complex_f3() (re float64, im float64) { im = 4.0 return } + +func (devnull) Write(p []byte) (n int, _ os.Error) { + n = len(p) + return +} </pre> </li> </ol> @@ -4259,11 +4257,13 @@ terminates </p> <pre> -L: for i < n { - switch i { - case 5: break L +L: + for i < n { + switch i { + case 5: + break L + } } -} </pre> <h3 id="Continue_statements">Continue statements</h3> @@ -4305,8 +4305,8 @@ instance, this example: </p> <pre> -goto L // BAD -v := 3 + goto L // BAD + v := 3 L: </pre> @@ -4396,8 +4396,7 @@ BuiltinCall = identifier "(" [ BuiltinArgs [ "," ] ] ")" . BuiltinArgs = Type [ "," ExpressionList ] | ExpressionList . </pre> -<!-- TODO(rsc): s/.and.closed//g --> -<h3 id="Close_and_closed">Close and closed</h3> +<h3 id="Close">Close</h3> <p> For a channel <code>c</code>, the built-in function <code>close(c)</code> @@ -4407,12 +4406,8 @@ After calling <code>close</code>, and after any previously sent values have been received, receive operations will return the zero value for the channel's type without blocking. -<!-- TODO(rsc): delete next sentence, replace with - The multi-valued <a href="#Receive_operator">receive operation</a> - returns a received value along with an indication of whether the channel is closed. ---> -After at least one such zero value has been -received, <code>closed(c)</code> returns true. +The multi-valued <a href="#Receive_operator">receive operation</a> +returns a received value along with an indication of whether the channel is closed. </p> @@ -4700,7 +4695,7 @@ func protect(g func()) { if x := recover(); x != nil { log.Printf("run time panic: %v", x) } - } + }() log.Println("start") g() } @@ -5152,6 +5147,4 @@ The following minimal alignment properties are guaranteed: <h2 id="Implementation_differences"><span class="alert">Implementation differences - TODO</span></h2> <ul> <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li> - <li><span class="alert">Gccgo: Method expressions are partially implemented.</span></li> - <li><span class="alert">Gccgo: allows only one init() function per source file.</span></li> </ul> |