doc/go_spec.html | 82 +++++++++++++++++++++++++++++++++++------------------ diff --git a/doc/go_spec.html b/doc/go_spec.html index 87ee7459ff73d109eb9bf7380aa02ec0ebc95bf4..bc9ec682a0a501cc49e269d8fdfde8b7efdad541 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1456,10 +1456,6 @@ by a value of type T. -

-Any value may be assigned to the blank identifier. -

-

Blocks

@@ -1514,6 +1510,11 @@ package. Every identifier in a program must be declared. No identifier may be declared twice in the same block, and no identifier may be declared in both the file and package block. +

+ +

+The blank identifier may be used like any other identifier +in a declaration, but it does not introduce a binding and thus is not declared.

@@ -1585,8 +1586,10 @@
 

Blank identifier

-The blank identifier, represented by the underscore character _, may be used in a declaration like -any other identifier but the declaration does not introduce a new binding. +The blank identifier is represented by the underscore character _. +It serves as an anonymous placeholder instead of a regular (non-blank) +identifier and has special meaning in declarations, +as an operand, and in assignments.

@@ -2077,13 +2080,18 @@

Operands

Operands denote the elementary values in an expression. An operand may be a -literal, a (possibly qualified) identifier -denoting a +literal, a (possibly qualified) +non-blank identifier denoting a constant, variable, or function, a method expression yielding a function, or a parenthesized expression. +

+ +

+The blank identifier may appear as an +operand only on the left-hand side of an assignment.

@@ -4255,7 +4263,8 @@ 

Each left-hand side operand must be addressable, -a map index expression, or the blank identifier. +a map index expression, or (for = assignments only) the +blank identifier. Operands may be parenthesized.

@@ -4268,12 +4277,13 @@

An assignment operation x op= -y where op is a binary arithmetic operation is equivalent +y where op is a binary arithmetic operation equivalent to x = x op y but evaluates x only once. The op= construct is a single token. In assignment operations, both the left- and right-hand expression lists -must contain exactly one single-valued expression. +must contain exactly one single-valued expression, and the left-hand +expression must not be the blank identifier.

@@ -4298,20 +4308,25 @@ 

assigns the first value to x and the second to y. -The blank identifier provides a -way to ignore values returned by a multi-valued expression: +In the second form, the number of operands on the left must equal the number +of expressions on the right, each of which must be single-valued, and the +nth expression on the right is assigned to the nth +operand on the left:

-x, _ = f()  // ignore second value returned by f()
+one, two, three = '一', '二', '三'
 

-In the second form, the number of operands on the left must equal the number -of expressions on the right, each of which must be single-valued, and the -nth expression on the right is assigned to the nth -operand on the left. +The blank identifier provides a way to +ignore right-hand side values in an assignment:

+ +
+_ = x       // evaluate x but ignore it
+x, _ = f()  // evaluate f() but ignore second result value
+

The assignment proceeds in two phases. @@ -4350,16 +4365,29 @@ // after this loop, i == 0 and x == []int{3, 5, 3}

-In assignments, each value must be -assignable to the type of the -operand to which it is assigned. If an untyped constant -is assigned to a variable of interface type, the constant is converted -to type bool, rune, int, float64, -complex128 or string -respectively, depending on whether the value is a -boolean, rune, integer, floating-point, complex, or string constant. +In assignments, each value must be assignable +to the type of the operand to which it is assigned, with the following special cases:

+
    +
  1. + If an untyped constant + is assigned to a variable of interface type or the blank identifier, + the constant is first converted to type + bool, rune, int, float64, + complex128 or string respectively, depending on + whether the value is a boolean, rune, integer, floating-point, complex, or + string constant. +

  2. + +
  3. + + If a left-hand side is the blank identifier, any typed or non-constant + value except for the predeclared identifier + nil + may be assigned to it. +

  4. +

If statements