summaryrefslogtreecommitdiff
path: root/doc/go_spec.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r--doc/go_spec.html306
1 files changed, 179 insertions, 127 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html
index 886f89d12..abf5b8f50 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,5 +1,5 @@
<!-- title The Go Programming Language Specification -->
-<!-- subtitle Version of Apr 22, 2011 -->
+<!-- subtitle Version of June 7, 2011 -->
<!--
TODO
@@ -10,7 +10,6 @@ TODO
[ ] clarify what a field name is in struct declarations
(struct{T} vs struct {T T} vs struct {t T})
[ ] need explicit language about the result type of operations
-[ ] may want to have some examples for the types of shift operations
[ ] should string(1<<s) and float32(1<<s) be valid?
[ ] should probably write something about evaluation order of statements even
though obvious
@@ -46,10 +45,10 @@ The syntax is specified using Extended Backus-Naur Form (EBNF):
</p>
<pre class="grammar">
-Production = production_name "=" Expression "." .
+Production = production_name "=" [ Expression ] "." .
Expression = Alternative { "|" Alternative } .
Alternative = Term { Term } .
-Term = production_name | token [ "..." token ] | Group | Option | Repetition .
+Term = production_name | token [ "…" token ] | Group | Option | Repetition .
Group = "(" Expression ")" .
Option = "[" Expression "]" .
Repetition = "{" Expression "}" .
@@ -73,8 +72,12 @@ double quotes <code>""</code> or back quotes <code>``</code>.
</p>
<p>
-The form <code>a ... b</code> represents the set of characters from
-<code>a</code> through <code>b</code> as alternatives.
+The form <code>a … b</code> represents the set of characters from
+<code>a</code> through <code>b</code> as alternatives. The horizontal
+ellipis … is also used elsewhere in the spec to informally denote various
+enumerations or code snippets that are not further specified. The character …
+(as opposed to the three characters <code>...</code>) is not a token of the Go
+language.
</p>
<h2 id="Source_code_representation">Source code representation</h2>
@@ -102,7 +105,8 @@ compiler may disallow the NUL character (U+0000) in the source text.
The following terms are used to denote specific Unicode character classes:
</p>
<pre class="ebnf">
-unicode_char = /* an arbitrary Unicode code point */ .
+newline = /* the Unicode code point U+000A */ .
+unicode_char = /* an arbitrary Unicode code point except newline */ .
unicode_letter = /* a Unicode code point classified as "Letter" */ .
unicode_digit = /* a Unicode code point classified as "Decimal Digit" */ .
</pre>
@@ -122,9 +126,9 @@ The underscore character <code>_</code> (U+005F) is considered a letter.
</p>
<pre class="ebnf">
letter = unicode_letter | "_" .
-decimal_digit = "0" ... "9" .
-octal_digit = "0" ... "7" .
-hex_digit = "0" ... "9" | "A" ... "F" | "a" ... "f" .
+decimal_digit = "0" … "9" .
+octal_digit = "0" … "7" .
+hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
</pre>
<h2 id="Lexical_elements">Lexical elements</h2>
@@ -286,7 +290,7 @@ An optional prefix sets a non-decimal base: <code>0</code> for octal, <code>0x</
</p>
<pre class="ebnf">
int_lit = decimal_lit | octal_lit | hex_lit .
-decimal_lit = ( "1" ... "9" ) { decimal_digit } .
+decimal_lit = ( "1" … "9" ) { decimal_digit } .
octal_lit = "0" { octal_digit } .
hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } .
</pre>
@@ -471,7 +475,7 @@ U+00FF.
<pre class="ebnf">
string_lit = raw_string_lit | interpreted_string_lit .
-raw_string_lit = "`" { unicode_char } "`" .
+raw_string_lit = "`" { unicode_char | newline } "`" .
interpreted_string_lit = `"` { unicode_value | byte_value } `"` .
</pre>
@@ -821,7 +825,7 @@ make([]T, length, capacity)
</pre>
<p>
-The <code>make()</code> call allocates a new, hidden array to which the returned
+A call to <code>make</code> allocates a new, hidden array to which the returned
slice value refers. That is, executing
</p>
@@ -1053,9 +1057,9 @@ have the method set
</p>
<pre>
-func (p T) Read(b Buffer) bool { return ... }
-func (p T) Write(b Buffer) bool { return ... }
-func (p T) Close() { ... }
+func (p T) Read(b Buffer) bool { return … }
+func (p T) Write(b Buffer) bool { return … }
+func (p T) Close() { … }
</pre>
<p>
@@ -1093,8 +1097,8 @@ If <code>S1</code> and <code>S2</code> also implement
</p>
<pre>
-func (p T) Lock() { ... }
-func (p T) Unlock() { ... }
+func (p T) Lock() { … }
+func (p T) Unlock() { … }
</pre>
<p>
@@ -1173,8 +1177,9 @@ make(map[string] int, 100)
<p>
The initial capacity does not bound its size:
maps grow to accommodate the number of items
-stored in them.
-</p>
+stored in them, with the exception of <code>nil</code> maps.
+A <code>nil</code> map is equivalent to an empty map except that no elements
+may be added.
<h3 id="Channel_types">Channel types</h3>
@@ -1233,6 +1238,7 @@ succeed without blocking if the buffer is not full (sends) or not empty (receive
and elements are received in the order they are sent.
If the capacity is zero or absent, the communication succeeds only when both a sender and
receiver are ready.
+A <code>nil</code> channel is never ready for communication.
</p>
<p>
@@ -1693,7 +1699,7 @@ of an interface type or of elements of a composite type remains unchanged:
</p>
<pre>
-// A Mutex is a data type with two methods Lock and Unlock.
+// A Mutex is a data type with two methods, Lock and Unlock.
type Mutex struct { /* Mutex fields */ }
func (m *Mutex) Lock() { /* Lock implementation */ }
func (m *Mutex) Unlock() { /* Unlock implementation */ }
@@ -1967,11 +1973,11 @@ package, which means that it must begin with a Unicode upper case letter.
math.Sin
</pre>
-<!---
+<!--
<p>
<span class="alert">TODO: Unify this section with Selectors - it's the same syntax.</span>
</p>
---->
+-->
<h3 id="Composite_literals">Composite literals</h3>
@@ -2096,7 +2102,7 @@ element index plus one. A slice literal has the form
</p>
<pre>
-[]T{x1, x2, ... xn}
+[]T{x1, x2, … xn}
</pre>
<p>
@@ -2104,7 +2110,7 @@ and is a shortcut for a slice operation applied to an array literal:
</p>
<pre>
-[n]T{x1, x2, ... xn}[0 : n]
+[n]T{x1, x2, … xn}[0 : n]
</pre>
<p>
@@ -2130,8 +2136,8 @@ parentheses.
</p>
<pre>
-if x == (T{a,b,c}[i]) { ... }
-if (x == T{a,b,c}[i]) { ... }
+if x == (T{a,b,c}[i]) { … }
+if (x == T{a,b,c}[i]) { … }
</pre>
<p>
@@ -2335,11 +2341,11 @@ p.M0 // ((*p).T0).M0
</pre>
-<!---
+<!--
<span class="alert">
TODO: Specify what happens to receivers.
</span>
---->
+-->
<h3 id="Indexes">Indexes</h3>
@@ -2368,7 +2374,7 @@ or for <code>a</code> of type <code>S</code> where <code>S</code> is a <a href="
<li><code>x</code> must be an integer value and <code>0 &lt;= x &lt; len(a)</code></li>
<li><code>a[x]</code> is the array element at index <code>x</code> and the type of
<code>a[x]</code> is the element type of <code>A</code></li>
- <li>if the index <code>x</code> is out of range,
+ <li>if <code>a</code> is <code>nil</code> or if the index <code>x</code> is out of range,
a <a href="#Run_time_panics">run-time panic</a> occurs</li>
</ul>
@@ -2396,7 +2402,7 @@ where <code>M</code> is a <a href="#Map_types">map type</a>:
<li>if the map contains an entry with key <code>x</code>,
<code>a[x]</code> is the map value with key <code>x</code>
and the type of <code>a[x]</code> is the value type of <code>M</code></li>
- <li>if the map does not contain such an entry,
+ <li>if the map is <code>nil</code> or does not contain such an entry,
<code>a[x]</code> is the <a href="#The_zero_value">zero value</a>
for the value type of <code>M</code></li>
</ul>
@@ -2425,7 +2431,7 @@ where the result of the index expression is a pair of values with types
</p>
<p>
-Similarly, if an assignment to a map has the special form
+Similarly, if an assignment to a map element has the special form
</p>
<pre>
@@ -2439,6 +2445,11 @@ the entry for key <code>x</code> is deleted from the map; if
a regular assignment to an element of the map.
</p>
+<p>
+Assigning to an element of a <code>nil</code> map causes a
+<a href="#Run_time_panics">run-time panic</a>.
+</p>
+
<h3 id="Slices">Slices</h3>
@@ -2559,11 +2570,11 @@ Given an expression <code>f</code> of function type
</p>
<pre>
-f(a1, a2, ... an)
+f(a1, a2, … an)
</pre>
<p>
-calls <code>f</code> with arguments <code>a1, a2, ... an</code>.
+calls <code>f</code> with arguments <code>a1, a2, … an</code>.
Except for one special case, arguments must be single-valued expressions
<a href="#Assignability">assignable</a> to the parameter types of
<code>F</code> and are evaluated before the function is called.
@@ -2642,7 +2653,7 @@ arguments bound to the final parameter and may differ for each call site.
Given the function and call
</p>
<pre>
-func Greeting(prefix string, who ... string)
+func Greeting(prefix string, who ...string)
Greeting("hello:", "Joe", "Anna", "Eileen")
</pre>
@@ -2693,42 +2704,39 @@ unary_op = "+" | "-" | "!" | "^" | "*" | "&amp;" | "&lt;-" .
<p>
Comparisons are discussed <a href="#Comparison_operators">elsewhere</a>.
For other binary operators, the operand types must be <a href="#Type_identity">identical</a>
-unless the operation involves channels, shifts, or untyped <a href="#Constants">constants</a>.
+unless the operation involves shifts or untyped <a href="#Constants">constants</a>.
For operations involving constants only, see the section on
<a href="#Constant_expressions">constant expressions</a>.
</p>
<p>
-In a channel send, the first operand is always a channel and the second
-must be a value <a href="#Assignability">assignable</a>
-to the channel's element type.
-</p>
-
-<p>
-Except for shift operations,
-if one operand is an untyped <a href="#Constants">constant</a>
+Except for shift operations, if one operand is an untyped <a href="#Constants">constant</a>
and the other operand is not, the constant is <a href="#Conversions">converted</a>
to the type of the other operand.
</p>
<p>
-The right operand in a shift operation must have unsigned integer type
+The right operand in a shift expression must have unsigned integer type
or be an untyped constant that can be converted to unsigned integer type.
-</p>
-
-<p>
-If the left operand of a non-constant shift operation is an untyped constant,
-the type of constant is what it would be if the shift operation were replaced by
-the left operand alone.
+If the left operand of a non-constant shift expression is an untyped constant,
+the type of the constant is what it would be if the shift expression were
+replaced by its left operand alone; the type is <code>int</code> if it cannot
+be determined from the context (for instance, if the shift expression is an
+operand in a comparison against an untyped constant).
</p>
<pre>
var s uint = 33
-var i = 1&lt;&lt;s // 1 has type int
-var j = int32(1&lt;&lt;s) // 1 has type int32; j == 0
-var u = uint64(1&lt;&lt;s) // 1 has type uint64; u == 1&lt;&lt;33
-var f = float32(1&lt;&lt;s) // illegal: 1 has type float32, cannot shift
-var g = float32(1&lt;&lt;33) // legal; 1&lt;&lt;33 is a constant shift operation; g == 1&lt;&lt;33
+var i = 1&lt;&lt;s // 1 has type int
+var j int32 = 1&lt;&lt;s // 1 has type int32; j == 0
+var k = uint64(1&lt;&lt;s) // 1 has type uint64; k == 1&lt;&lt;33
+var m int = 1.0&lt;&lt;s // legal: 1.0 has type int
+var n = 1.0&lt;&lt;s != 0 // legal: 1.0 has type int; n == false if ints are 32bits in size
+var o = 1&lt;&lt;s == 2&lt;&lt;s // legal: 1 and 2 have type int; o == true if ints are 32bits in size
+var p = 1&lt;&lt;s == 1&lt;&lt;33 // illegal if ints are 32bits in size: 1 has type int, but 1&lt;&lt;33 overflows int
+var u = 1.0&lt;&lt;s // illegal: 1.0 has type float64, cannot shift
+var v float32 = 1&lt;&lt;s // illegal: 1 has type float32, cannot shift
+var w int64 = 1.0&lt;&lt;33 // legal: 1.0&lt;&lt;33 is a constant shift expression
</pre>
<h3 id="Operator_precedence">Operator precedence</h3>
@@ -2808,15 +2816,18 @@ s += " and good bye"
String addition creates a new string by concatenating the operands.
</p>
<p>
-For integer values, <code>/</code> and <code>%</code> satisfy the following relationship:
+For two integer values <code>x</code> and <code>y</code>, the integer quotient
+<code>q = x / y</code> and remainder <code>r = x % y</code> satisfy the following
+relationships:
</p>
<pre>
-(a / b) * b + a % b == a
+x = q*y + r and |r| &lt; |y|
</pre>
<p>
-with <code>(a / b)</code> truncated towards zero.
+with <code>x / y</code> truncated towards zero
+(<a href="http://en.wikipedia.org/wiki/Modulo_operation">"truncated division"</a>).
</p>
<pre>
@@ -2828,6 +2839,20 @@ with <code>(a / b)</code> truncated towards zero.
</pre>
<p>
+As an exception to this rule, if the dividend <code>x</code> is the most
+negative value for the int type of <code>x</code>, the quotient
+<code>q = x / -1</code> is equal to <code>x</code> (and <code>r = 0</code>).
+</p>
+
+<pre>
+ x, q
+int8 -128
+int16 -32768
+int32 -2147483648
+int64 -9223372036854775808
+</pre>
+
+<p>
If the divisor is zero, a <a href="#Run_time_panics">run-time panic</a> occurs.
If the dividend is positive and the divisor is a constant power of 2,
the division may be replaced by a right shift, and computing the remainder may
@@ -2843,8 +2868,8 @@ be replaced by a bitwise "and" operation:
<p>
The shift operators shift the left operand by the shift count specified by the
right operand. They implement arithmetic shifts if the left operand is a signed
-integer and logical shifts if it is an unsigned integer. The shift count must
-be an unsigned integer. There is no upper limit on the shift count. Shifts behave
+integer and logical shifts if it is an unsigned integer.
+There is no upper limit on the shift count. Shifts behave
as if the left operand is shifted <code>n</code> times by 1 for a shift
count of <code>n</code>.
As a result, <code>x &lt;&lt; 1</code> is the same as <code>x*2</code>
@@ -3025,6 +3050,7 @@ For an operand <code>ch</code> of <a href="#Channel_types">channel type</a>,
the value of the receive operation <code>&lt;-ch</code> is the value received
from the channel <code>ch</code>. The type of the value is the element type of
the channel. The expression blocks until a value is available.
+Receiving from a <code>nil</code> channel blocks forever.
</p>
<pre>
@@ -3052,17 +3078,12 @@ 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
-<a href="#Run_time_panics">run-time panic</a>.
-</p>
-
-<!---
+<!--
<p>
<span class="alert">TODO: Probably in a separate section, communication semantics
need to be presented regarding send, receive, select, and goroutines.</span>
</p>
---->
+-->
<h3 id="Method_expressions">Method expressions</h3>
@@ -3360,21 +3381,35 @@ respectively. Except for shift operations, if the operands of a binary operation
are an untyped integer constant and an untyped floating-point constant,
the integer constant is converted to an untyped floating-point constant
(relevant for <code>/</code> and <code>%</code>).
-Similarly,
-untyped integer or floating-point constants may be used as operands
+Similarly, untyped integer or floating-point constants may be used as operands
wherever it is legal to use an operand of complex type;
the integer or floating point constant is converted to a
complex constant with a zero imaginary part.
</p>
<p>
-Applying an operator to untyped constants results in an untyped
+A constant <a href="#Comparison_operators">comparison</a> always yields
+a constant of type <code>bool</code>. If the left operand of a constant
+<a href="#Operators">shift expression</a> is an untyped constant, the
+result is an integer constant; otherwise it is a constant of the same
+type as the left operand, which must be of integer type
+(§<a href="#Arithmetic_operators">Arithmetic operators</a>).
+Applying all other operators to untyped constants results in an untyped
constant of the same kind (that is, a boolean, integer, floating-point,
-complex, or string constant), except for
-<a href="#Comparison_operators">comparison operators</a>, which result in
-a constant of type <code>bool</code>.
+complex, or string constant).
</p>
+<pre>
+const a = 2 + 3.0 // a == 5.0 (floating-point constant)
+const b = 15 / 4 // b == 3 (integer constant)
+const c = 15 / 4.0 // c == 3.75 (floating-point constant)
+const d = 1 &lt;&lt; 3.0 // d == 8 (integer constant)
+const e = 1.0 &lt;&lt; 3 // e == 8 (integer constant)
+const f = int32(1) &lt;&lt; 33 // f == 0 (type int32)
+const g = float64(2) &gt;&gt; 1 // illegal (float64(2) is a typed floating-point constant)
+const h = "foo" &gt; "bar" // h == true (type bool)
+</pre>
+
<p>
Imaginary literals are untyped complex constants (with zero real part)
and may be combined in binary
@@ -3431,7 +3466,7 @@ int8(^1) // same as int8(-2)
^int8(1) // same as -1 ^ int8(1) = -2
</pre>
-<!---
+<!--
<p>
<span class="alert">
TODO: perhaps ^ should be disallowed on non-uints instead of assuming twos complement.
@@ -3439,7 +3474,7 @@ Also it may be possible to make typed constants more like variables, at the cost
overflow etc. errors being caught.
</span>
</p>
---->
+-->
<h3 id="Order_of_evaluation">Order of evaluation</h3>
@@ -3522,10 +3557,9 @@ Error: log.Panic("error encountered")
<p>
Function calls, method calls, and receive operations
-can appear in statement context.
+can appear in statement context. Such statements may be parenthesized.
</p>
-
<pre class="ebnf">
ExpressionStmt = Expression .
</pre>
@@ -3534,6 +3568,7 @@ ExpressionStmt = Expression .
h(x+y)
f.Close()
&lt;-ch
+(&lt;-ch)
</pre>
@@ -3557,17 +3592,13 @@ begins. Communication blocks until the send can proceed, at which point the
value is transmitted on the channel.
A send on an unbuffered channel can proceed if a receiver is ready.
A send on a buffered channel can proceed if there is room in the buffer.
+A send on a <code>nil</code> channel blocks forever.
</p>
<pre>
ch &lt;- 3
</pre>
-<p>
-Sending to a <code>nil</code> channel causes a
-<a href="#Run_time_panics">run-time panic</a>.
-</p>
-
<h3 id="IncDec_statements">IncDec statements</h3>
@@ -3604,15 +3635,15 @@ assign_op = [ add_op | mul_op ] "=" .
<p>
Each left-hand side operand must be <a href="#Address_operators">addressable</a>,
-a map index expression,
-or the <a href="#Blank_identifier">blank identifier</a>.
+a map index expression, or the <a href="#Blank_identifier">blank identifier</a>.
+Operands may be parenthesized.
</p>
<pre>
x = 1
*p = f()
a[i] = 23
-k = &lt;-ch
+(k) = &lt;-ch // same as: k = &lt;-ch
</pre>
<p>
@@ -3966,10 +3997,14 @@ As with an assignment, the operands on the left must be
<a href="#Address_operators">addressable</a> or map index expressions; they
denote the iteration variables. If the range expression is a channel, only
one iteration variable is permitted, otherwise there may be one or two.
+If the second iteration variable is the <a href="#Blank_identifier">blank identifier</a>,
+the range clause is equivalent to the same clause with only the first variable present.
</p>
<p>
-The range expression is evaluated once before beginning the loop.
+The range expression is evaluated once before beginning the loop
+except if the expression is an array, in which case, depending on
+the expression, it might not be evaluated (see below).
Function calls on the left are evaluated once per iteration.
For each iteration, iteration values are produced as follows:
</p>
@@ -3985,8 +4020,11 @@ channel c chan E element e E
<ol>
<li>
-For an array or slice value, the index iteration values are produced in
-increasing order, starting at element index 0.
+For an array, pointer to array, or slice value <code>a</code>, the index iteration
+values are produced in increasing order, starting at element index 0. As a special
+case, if only the first iteration variable is present, the range loop produces
+iteration values from 0 up to <code>len(a)</code> and does not index into the array
+or slice itself. For a <code>nil</code> slice, the number of iterations is 0.
</li>
<li>
@@ -4005,13 +4043,14 @@ The iteration order over maps is not specified.
If map entries that have not yet been reached are deleted during iteration,
the corresponding iteration values will not be produced. If map entries are
inserted during iteration, the behavior is implementation-dependent, but the
-iteration values for each entry will be produced at most once.
+iteration values for each entry will be produced at most once. If the map
+is <code>nil</code>, the number of iterations is 0.
</li>
<li>
For channels, the iteration values produced are the successive values sent on
-the channel until the channel is closed
-(§<a href="#Close"><code>close</code>).
+the channel until the channel is <a href="#Close">closed</a>. If the channel
+is <code>nil</code>, the range expression blocks forever.
</li>
</ol>
@@ -4030,9 +4069,17 @@ after execution their values will be those of the last iteration.
</p>
<pre>
+var testdata *struct {
+ a *[7]int
+}
+for i, _ := range testdata.a {
+ // testdata.a is never evaluated; len(testdata.a) is constant
+ // i ranges from 0 to 6
+ f(i)
+}
+
var a [10]string
m := map[string]int{"mon":0, "tue":1, "wed":2, "thu":3, "fri":4, "sat":5, "sun":6}
-
for i, s := range a {
// type of i is int
// type of s is string
@@ -4047,6 +4094,11 @@ for key, val = range m {
}
// key == last map key encountered in iteration
// val == map[key]
+
+var ch chan Work = producer()
+for w := range ch {
+ doWork(w)
+}
</pre>
@@ -4131,7 +4183,7 @@ case i1 = &lt;-c1:
print("received ", i1, " from c1\n")
case c2 &lt;- i2:
print("sent ", i2, " to c2\n")
-case i3, ok := &lt;-c3:
+case i3, ok := (&lt;-c3): // same as: i3, ok := &lt;-c3
if ok {
print("received ", i3, " from c3\n")
} else {
@@ -4229,7 +4281,7 @@ func (devnull) Write(p []byte) (n int, _ os.Error) {
Regardless of how they are declared, all the result values are initialized to the zero values for their type (§<a href="#The_zero_value">The zero value</a>) upon entry to the function.
</p>
-<!---
+<!--
<p>
<span class="alert">
TODO: Define when return is required.<br />
@@ -4237,7 +4289,7 @@ TODO: Language about result parameters needs to go into a section on
function/method invocation<br />
</span>
</p>
---->
+-->
<h3 id="Break_statements">Break statements</h3>
@@ -4314,9 +4366,9 @@ L:
<p>
is erroneous because the jump to label <code>L</code> skips
the creation of <code>v</code>.
-<!---
+<!--
(<span class="alert">TODO: Eliminate in favor of used and not set errors?</span>)
---->
+-->
</p>
<h3 id="Fallthrough_statements">Fallthrough statements</h3>
@@ -4421,17 +4473,17 @@ The implementation guarantees that the result always fits into an <code>int</cod
</p>
<pre class="grammar">
-Call Argument type Result
+Call Argument type Result
-len(s) string type string length in bytes
- [n]T, *[n]T array length (== n)
- []T slice length
- map[K]T map length (number of defined keys)
- chan T number of elements queued in channel buffer
+len(s) string type string length in bytes
+ [n]T, *[n]T array length (== n)
+ []T slice length
+ map[K]T map length (number of defined keys)
+ chan T number of elements queued in channel buffer
-cap(s) [n]T, *[n]T array length (== n)
- []T slice capacity
- chan T channel buffer capacity
+cap(s) [n]T, *[n]T array length (== n)
+ []T slice capacity
+ chan T channel buffer capacity
</pre>
<p>
@@ -4449,20 +4501,17 @@ The length and capacity of a <code>nil</code> slice, map, or channel are 0.
</p>
<p>
-The expression
-<code>len(s)</code> is a
-<a href="#Constants">constant</a> if <code>s</code> is a string constant.
-The expressions
-<code>len(s)</code> and
-<code>cap(s)</code> are
-constants if <code>s</code> is an (optionally parenthesized)
-identifier or
-<a href="#Qualified_identifiers">qualified identifier</a>
-denoting an array or pointer to array.
-Otherwise invocations of <code>len</code> and <code>cap</code> are not
-constant.
+The expression <code>len(s)</code> is <a href="#Constants">constant</a> if
+<code>s</code> is a string constant. The expressions <code>len(s)</code> and
+<code>cap(s)</code> are constants if the type of <code>s</code> is an array
+or pointer to an array and the expression <code>s</code> does not contain
+<a href="#Receive_operator">channel receives</a> or
+<a href="#Calls">function calls</a>; in this case <code>s</code> is not evaluated.
+Otherwise, invocations of <code>len</code> and <code>cap</code> are not
+constant and <code>s</code> is evaluated.
</p>
+
<h3 id="Allocation">Allocation</h3>
<p>
@@ -4575,7 +4624,7 @@ a source <code>src</code> to a destination <code>dst</code> and returns the
number of elements copied. Source and destination may overlap.
Both arguments must have <a href="#Type_identity">identical</a> element type <code>T</code> and must be
<a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>.
-The number of arguments copied is the minimum of
+The number of elements copied is the minimum of
<code>len(src)</code> and <code>len(dst)</code>.
As a special case, <code>copy</code> also accepts a destination argument assignable
to type <code>[]byte</code> with a source argument of a string type.
@@ -4850,7 +4899,7 @@ package main
import "fmt"
-// Send the sequence 2, 3, 4, ... to channel 'ch'.
+// Send the sequence 2, 3, 4, … to channel 'ch'.
func generate(ch chan&lt;- int) {
for i := 2; ; i++ {
ch &lt;- i // Send 'i' to channel 'ch'.
@@ -4890,7 +4939,7 @@ func main() {
<h3 id="The_zero_value">The zero value</h3>
<p>
When memory is allocated to store a value, either through a declaration
-or <code>make()</code> or <code>new()</code> call,
+or a call of <code>make</code> or <code>new</code>,
and no explicit initialization is provided, the memory is
given a default initialization. Each element of such a value is
set to the <i>zero value</i> for its type: <code>false</code> for booleans,
@@ -4948,7 +4997,7 @@ func init()
<p>
defined in its source.
A package may contain multiple
-<code>init()</code> functions, even
+<code>init</code> functions, even
within a single source file; they execute
in unspecified order.
</p>
@@ -4978,8 +5027,8 @@ program is complete. Therefore, all initialization code is run in a single
goroutine.
</p>
<p>
-An <code>init()</code> function cannot be referred to from anywhere
-in a program. In particular, <code>init()</code> cannot be called explicitly,
+An <code>init</code> function cannot be referred to from anywhere
+in a program. In particular, <code>init</code> cannot be called explicitly,
nor can a pointer to <code>init</code> be assigned to a function variable.
</p>
<p>
@@ -5001,7 +5050,7 @@ arguments and returns no value.
</p>
<pre>
-func main() { ... }
+func main() { … }
</pre>
<p>
@@ -5151,5 +5200,8 @@ 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">The restriction on <code>goto</code> statements and targets (no intervening declarations) is not honored.</span></li>
+ <li><span class="alert"><code>len(a)</code> is only a constant if <code>a</code> is a (qualified) identifier denoting an array or pointer to an array.</span></li>
+ <li><span class="alert"><code>nil</code> maps are not treated like empty maps.</span></li>
+ <li><span class="alert">Trying to send/receive from a <code>nil</code> channel causes a run-time panic.</span></li>
</ul>