From 4e56b33b42bb524f2b80bc1bded1d42bc98c4bd9 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 10 Sep 2009 10:14:00 -0700 Subject: [PATCH] - blank identifier - fixed some links DELTA=51 (32 added, 1 deleted, 18 changed) OCL=34497 CL=34515 --- doc/go_spec.html | 65 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 910f8651fa1..9498c4cf984 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -167,7 +167,7 @@ _x9 ThisVariableIsExported αβ -Some identifiers are predeclared (§Predeclared identifiers). +Some identifiers are predeclared.

Keywords

@@ -665,8 +665,8 @@ new([100]int)[0:50]

A struct is a sequence of named elements, called fields, with various types. A struct type declares -an identifier and type for each field. Within a struct, field identifiers -must be unique. +an identifier and type for each field. Within a struct, non-blank +field identifiers must be unique.

@@ -680,10 +680,11 @@ Tag = StringLit .
 // An empty struct.
 struct {}
 
-// A struct with 5 fields.
+// A struct with 6 fields.
 struct {
 	x, y int;
 	u float;
+	_ float;  // padding
 	A *[]int;
 	F func();
 }
@@ -1168,6 +1169,9 @@ A bidirectional channel c can be assigned to a channel variable
 v with compatible channel value type
 if the type of c or v is unnamed.
 
+
  • +A value can always be assigned to the blank identifier. +
  • Comparison compatibility

    @@ -1244,7 +1248,7 @@ In addition to explicit blocks in the source code, there are implicit blocks:
    1. The universe block encompasses all Go source text.
    2. -
    3. Each package (§Packages) has a package block containing all +
    4. Each package has a package block containing all Go source text for that package.
    5. Each file has a file block containing all Go source text @@ -1258,14 +1262,15 @@ In addition to explicit blocks in the source code, there are implicit blocks:

    -Blocks nest and influence scoping (§Declarations and scope). +Blocks nest and influence scoping.

    Declarations and scope

    -A declaration binds an identifier to a constant, type, variable, function, or package. +A declaration binds a non-blank +identifier to a constant, type, variable, function, or 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. @@ -1372,6 +1377,14 @@ All other identifiers are not exported.

    +

    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. +

    + +

    Const declarations

    @@ -1449,7 +1462,7 @@ set of related constants:

    -const (            // iota is reset to 0
    +const (  // iota is reset to 0
     	c0 = iota;  // c0 == 0
     	c1 = iota;  // c1 == 1
     	c2 = iota   // c2 == 2
    @@ -1480,7 +1493,8 @@ it is only incremented at a semicolon:
     const (
     	bit0, mask0 = 1 << iota, 1 << iota - 1;  // bit0 == 1, mask0 == 0
     	bit1, mask1;                             // bit1 == 2, mask1 == 1
    -	bit2, mask2;                             // bit2 == 4, mask2 == 3
    +	_, _;                                    // skips iota == 2
    +	bit3, mask3;                             // bit3 == 8, mask3 == 7
     )
     
    @@ -1542,6 +1556,8 @@ var ( i int; u, v, s = 2.0, 3.0, "bar" ) +var re, im = complexSqrt(-1) +var _, found = entries[name]; // map lookup; only interested in "found"

    @@ -1589,12 +1605,13 @@ i, j := 0, 10; f := func() int { return 7; } ch := make(chan int); r, w := os.Pipe(fd); // os.Pipe() returns two values +_, y, _ := coord(p); // coord() returns three values; only interested in y "projection"

    Unlike regular variable declarations, a short variable declaration may redeclare variables provided they were originally declared in the same block with the same type, and at -least one of the variables is new. As a consequence, redeclaration +least one of the non-blank variables is new. As a consequence, redeclaration can only appear in a multi-variable short declaration. Redeclaration does not introduce a new variable; it just assigns a new value to the original. @@ -1734,12 +1751,11 @@ Constants have values that are known at compile time.

    Qualified identifiers

    -A qualified identifier is an identifier qualified by a package name prefix. +A qualified identifier is a non-blank identifier qualified by a package name prefix.

     QualifiedIdent = [ PackageName "." ] identifier .
    -PackageName = identifier .
     

    @@ -1752,6 +1768,10 @@ package, which means that it must begin with a Unicode upper case letter. Math.Sin +

    +TODO: Unify this section with Selectors - it's the same syntax. +

    +

    Composite literals

    @@ -1998,7 +2018,7 @@ denotes the field or method f of the value denoted by x*x if x is of pointer type). The identifier f is called the (field or method) -selector. +selector; it must not be the blank identifier. The type of the expression is the type of f.

    @@ -3096,7 +3116,7 @@ assign_op = [ add_op | mul_op ] "=" .

    Each left-hand side operand must be a variable, pointer indirection, -field selector, or index expression. +field selector, index expression, or blank identifier.

    @@ -3126,7 +3146,7 @@ first, the right hand operand is a single multi-valued expression
     such as a function evaluation or channel or
     map operation or a type assertion.
     The number of operands on the left
    -hand side must match the number of values.  For instance, If
    +hand side must match the number of values.  For instance, if
     f is a function returning two values,
     

    @@ -3136,8 +3156,14 @@ x, y = f()

    assigns the first value to x and the second to y. +The blank identifier provides a convenient +way to ignore values returned by a multi-valued expression:

    +
    +x, _ = f()  // ignore second value returned by f()
    +
    +

    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 @@ -3998,7 +4024,7 @@ m := make(map[string] int, 100); # map with initial space for 100 elements Go programs are constructed by linking together packages. A package is in turn constructed from one or more source files that together provide access to a set of types, constants, functions, -and variables. Those elements may be imported and used in +and variables. Those elements may be exported and used in another package.

    @@ -4024,9 +4050,14 @@ to which the file belongs.

    -PackageClause    = "package" PackageName .
    +PackageClause  = "package" PackageName .
    +PackageName    = identifier .
     
    +

    +The PackageName must not be the blank identifier. +

    +
     package math