From 7c4f7cc7eb662d08a73c5e69407067c71e03adc3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 20 Aug 2009 11:11:03 -0700 Subject: [PATCH] introduce meaningful section names, so that go_spec.html#Return_statements can be used to link to spec sections. passes hlint. renamed final section to simply "Implementation differences" to shorten the name, but otherwise no non-formatting changes R=gri DELTA=230 (10 added, 0 deleted, 220 changed) OCL=33598 CL=33598 --- doc/go_spec.html | 374 +++++++++++++++++++++++------------------------ 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 0f7d6cc6bb..789232c6a0 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -26,7 +26,7 @@ Todo's: --> -

Introduction

+

Introduction

This is a reference manual for the Go programming language. For @@ -48,7 +48,7 @@ The grammar is compact and regular, allowing for easy analysis by automatic tools such as integrated development environments.


-

Notation

+

Notation

The syntax is specified using Extended Backus-Naur Form (EBNF):

@@ -87,7 +87,7 @@ The form a ... b represents the set of characters from
-

Source code representation

+

Source code representation

Source code is Unicode text encoded in UTF-8. The text is not @@ -101,7 +101,7 @@ Each code point is distinct; for instance, upper and lower case letters are different characters.

-

Characters

+

Characters

The following terms are used to denote specific Unicode character classes: @@ -114,7 +114,7 @@ unicode_digit = /* a Unicode code point classified as "Digit" */ . (The Unicode Standard, Section 4.5 General Category - Normative.) -

Letters and digits

+

Letters and digits

The underscore character _ (U+005F) is considered a letter. @@ -127,9 +127,9 @@ hex_digit = "0" ... "9" | "A" ... "F" | "a" ... "f" .


-

Lexical elements

+

Lexical elements

-

Comments

+

Comments

There are two forms of comments. The first starts at the character @@ -138,7 +138,7 @@ second starts at the character sequence /* and continues through the character sequence */. Comments do not nest.

-

Tokens

+

Tokens

Tokens form the vocabulary of the Go language. @@ -151,7 +151,7 @@ the next token is the longest sequence of characters that form a valid token.

-

Identifiers

+

Identifiers

Identifiers name program entities such as variables and types. @@ -167,9 +167,9 @@ _x9 ThisVariableIsExported αβ -Some identifiers are predeclared (§Predeclared identifiers). +Some identifiers are predeclared (§Predeclared identifiers). -

Keywords

+

Keywords

The following keywords are reserved and may not be used as identifiers. @@ -182,7 +182,7 @@ const fallthrough if range type continue for import return var -

Operators and Delimiters

+

Operators and Delimiters

The following character sequences represent operators, delimiters, and other special tokens: @@ -196,7 +196,7 @@ The following character sequences represent operators, delimiters, and other spe &^ &^= -

Integer literals

+

Integer literals

An integer literal is a sequence of one or more digits in the @@ -219,7 +219,7 @@ hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } . 170141183460469231731687303715884105727 -

Floating-point literals

+

Floating-point literals

A floating-point literal is a decimal representation of a floating-point number. It has an integer part, a decimal point, a fractional part, @@ -247,7 +247,7 @@ exponent = ( "e" | "E" ) [ "+" | "-" ] decimals . .12345E+5 -

Ideal numbers

+

Ideal numbers

Integer literals represent values of arbitrary precision, or ideal @@ -263,7 +263,7 @@ by choosing an internal representation with at least twice the precision of any machine type.

-

Character literals

+

Character literals

A character literal represents an integer value, typically a @@ -348,12 +348,12 @@ The value of a character literal is an ideal integer, just as with integer literals.

-

String literals

+

String literals

String literals represent ideal string values. Ideal strings don't have a named type but they are compatible with type string -(§Type identity and compatibility). +(§Type identity and compatibility). There are two forms: raw string literals and interpreted string literals.

@@ -427,12 +427,12 @@ literal.


-

Types

+

Types

A type determines the set of values and operations specific to values of that type. A type may be specified by a (possibly qualified) type name -(§Qualified identifier, §Type declarations) or a type literal, +(§Qualified identifier, §Type declarations) or a type literal, which composes a new type from previously declared types.

@@ -444,7 +444,7 @@ TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType

-Basic types such as int are predeclared (§Predeclared identifiers). +Basic types such as int are predeclared (§Predeclared identifiers). Other types may be constructed from these, recursively, including arrays, structs, pointers, functions, interfaces, slices, maps, and channels. @@ -452,8 +452,8 @@ channels.

A type may have a method set associated with it -(§Interface types, §Method declarations). -The method set of an interface type (§Interface types) is its interface. +(§Interface types, §Method declarations). +The method set of an interface type (§Interface types) is its interface. The method set of any other named type T consists of all methods with receiver type T. @@ -465,20 +465,20 @@ Any other type has an empty method set.

The static type (or just type) of a variable is the type defined by its declaration. Variables of interface type -(§Interface types) also have a distinct dynamic type, which +(§Interface types) also have a distinct dynamic type, which is the actual type of the value stored in the variable at run-time. The dynamic type may vary during execution but is always compatible with the static type of the interface variable. For non-interface types, the dynamic type is always the static type.

-

Basic types

+

Basic types

Basic types include traditional numeric types, booleans, and strings. All are predeclared.

-

Numeric types

+

Numeric types

The architecture-independent numeric types are: @@ -528,14 +528,14 @@ are not the same type even though they may have the same size on a particular architecture. -

Booleans

+

Booleans

The type bool comprises the Boolean truth values represented by the predeclared constants true and false. -

Strings

+

Strings

The string type represents the set of string values. @@ -544,7 +544,7 @@ it is impossible to change the contents of a string.

The elements of strings have type byte and may be -accessed using the usual indexing operations (§Indexes). It is +accessed using the usual indexing operations (§Indexes). It is illegal to take the address of such an element, that is, even if s[i] is the ith byte of a string, &s[i] is invalid. The length of string @@ -554,7 +554,7 @@ is a string literal.

-

Array types

+

Array types

An array is a numbered sequence of elements of a single @@ -571,11 +571,11 @@ ElementType = Type .

The length is part of the array's type and must must be a constant -expression (§Constant expressions) that evaluates to a non-negative +expression (§Constant expressions) that evaluates to a non-negative integer value. The length of array a can be discovered using the built-in function len(a), which is a compile-time constant. The elements can be indexed by integer -indices 0 through the len(a)-1 (§Indexes). +indices 0 through the len(a)-1 (§Indexes).

@@ -584,7 +584,7 @@ indices 0 through the len(a)-1 (§Indexes).
 [1000]*float64
 
-

Slice types

+

Slice types

A slice is a reference to a contiguous segment of an array and @@ -602,7 +602,7 @@ Like arrays, slices are indexable and have a length. The length of a slice s can be discovered by the built-in function len(s); unlike with arrays it may change during execution. The elements can be addressed by integer indices 0 -through len(s)-1 (§Indexes). The slice index of a +through len(s)-1 (§Indexes). The slice index of a given element may be less than the index of the same element in the underlying array.

@@ -617,7 +617,7 @@ The array underlying a slice may extend past the end of the slice. The capacity is a measure of that extent: it is the sum of the length of the slice and the length of the array beyond the slice; a slice of length up to that capacity can be created by `slicing' a new -one from the original slice (§Slices). +one from the original slice (§Slices). The capacity of a slice a can be discovered using the built-in function cap(a) and the relationship between len() and cap() is: @@ -660,7 +660,7 @@ new([100]int)[0:50] -

Struct types

+

Struct types

A struct is a sequence of named @@ -723,8 +723,8 @@ struct {

-Fields and methods (§Method declarations) of an anonymous field are -promoted to be ordinary fields and methods of the struct (§Selectors). +Fields and methods (§Method declarations) of an anonymous field are +promoted to be ordinary fields and methods of the struct (§Selectors). The following rules apply for a struct type named S and a type named T:

@@ -762,7 +762,7 @@ struct { } -

Pointer types

+

Pointer types

A pointer type denotes the set of all pointers to variables of a given @@ -780,7 +780,7 @@ BaseType = Type . *map[string] *chan int -

Function types

+

Function types

A function type denotes the set of all functions with the same parameter @@ -826,7 +826,7 @@ func (n int) (func (p* T)) -

Interface types

+

Interface types

An interface type specifies a method set called its interface. @@ -881,7 +881,7 @@ interface { }

Similarly, consider this interface specification, -which appears within a type declaration (§Type declarations) +which appears within a type declaration (§Type declarations) to define an interface called Lock:

@@ -924,7 +924,7 @@ type File interface { } -

Map types

+

Map types

A map is an unordered group of elements of one type, called the @@ -942,7 +942,7 @@ ValueType = Type .

The comparison operators == and != -(§Comparison operators) must be fully defined for operands of the +(§Comparison operators) must be fully defined for operands of the key type; thus the key type must be a basic, pointer, interface, map, or channel type. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; @@ -964,7 +964,7 @@ The value of an uninitialized map is nil.

Upon creation, a map is empty. Values may be added and removed -during execution using special forms of assignment (§Assignments). +during execution using special forms of assignment (§Assignments). A new, empty map value is made using the built-in function make, which takes the map type and an optional capacity hint as arguments: @@ -981,7 +981,7 @@ maps grow to accommodate the number of items stored in them.

-

Channel types

+

Channel types

A channel provides a mechanism for two concurrently executing functions @@ -1037,7 +1037,7 @@ the zero value for the channel's type. After at least one such zero value has b received, closed(c) returns true.

-

General properties of types and values

+

General properties of types and values

Two types may be identical, compatible, or incompatible. @@ -1046,13 +1046,13 @@ Go is type safe: a value of one type cannot be assigned to a variable of incompatible type, and two values of incompatible types cannot be mixed in binary operations.

-

Type identity and compatibility

+

Type identity and compatibility

-

Type identity

+

Type identity

Two named types are identical if their type names originate in the same -type declaration (§Declarations and Scope). A named and an unnamed type +type declaration (§Declarations and Scope). A named and an unnamed type are never identical. Two unnamed types are identical if the corresponding type literals have the same literal structure and corresponding components have identical types. In detail: @@ -1085,7 +1085,7 @@ identical types. In detail: the same direction. -

Type compatibility

+

Type compatibility

Type compatibility is less stringent than type identity: a named and an unnamed @@ -1142,7 +1142,7 @@ T4 and func (x int, y float) *[]string they have different field names.

-

Assignment compatibility

+

Assignment compatibility

Values of any type may always be assigned to variables @@ -1170,12 +1170,12 @@ if the type of c or v is unnamed. -

Comparison compatibility

+

Comparison compatibility

Values of any type may be compared to other values of compatible static type. Values of numeric and string type may be compared using the -full range of comparison operators as described in §Comparison operators; +full range of comparison operators as described in §Comparison operators; booleans may be compared only for equality or inequality.

@@ -1214,7 +1214,7 @@ Function values are equal if they refer to the same function.
  • Channel and map values are equal if they were created by the same call to make -(§Making slices, maps, and channels). +(§Making slices, maps, and channels).
  • Interface values may be compared if they have compatible static types. @@ -1224,7 +1224,7 @@ They will be equal only if they have the same dynamic type and the underlying va
    -

    Blocks

    +

    Blocks

    A block is a sequence of declarations and statements within matching @@ -1242,7 +1242,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 (§Packages) has a package block containing all Go source text for that package.
    5. Each file has a file block containing all Go source text @@ -1256,11 +1256,11 @@ 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).

    -

    Declarations and Scope

    +

    Declarations and Scope

    A declaration binds an identifier to a constant, type, variable, function, or package. @@ -1312,19 +1312,19 @@ the entity declared by the inner declaration.

    -The package clause (§Package clause) is not a declaration; the package name +The package clause (§Package clause) is not a declaration; the package name does not appear in any scope. Its purpose is to identify the files belonging -to the same package (§Packages) and to specify the default name for import +to the same package (§Packages) and to specify the default name for import declarations.

    -

    Label scopes

    +

    Label scopes

    -Labels are declared by labeled statements (§Labeled statements) and are +Labels are declared by labeled statements (§Labeled statements) and are used in the break, continue, and goto -statements (§Break statements, §Continue statements, §Goto statements). +statements (§Break statements, §Continue statements, §Goto statements). 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 @@ -1332,7 +1332,7 @@ the body of any nested function.

    -

    Predeclared identifiers

    +

    Predeclared identifiers

    The following identifiers are implicitly declared in the universe block: @@ -1355,12 +1355,12 @@ Packages: unsafe -

    Exported identifiers

    +

    Exported identifiers

    By default, identifiers are visible only within the package in which they are declared. Some identifiers are exported and can be referenced using -qualified identifiers in other packages (§Qualified identifiers). +qualified identifiers in other packages (§Qualified identifiers). If an identifier satisfies these two conditions:

      @@ -1372,12 +1372,12 @@ declared at the top level; it will be exported.

      -

      Const declarations

      +

      Const declarations

      A constant declaration binds a list of identifiers (the names of the constants) to the values of a list of constant expressions -(§Constant expressions). The number of identifiers must be equal +(§Constant expressions). The number of identifiers must be equal to the number of expressions, and the nth identifier on the left is bound to value of the nth expression on the right. @@ -1395,7 +1395,7 @@ ExpressionList = Expression { "," Expression } .

      If the type is omitted, the constants take the individual types of the corresponding expressions, which may be -ideal integer or ideal float (§Ideal number). If the type +ideal integer or ideal float (§Ideal number). If the type is present, all constants take the type specified, and the types of all the expressions must be assignment-compatible with that type. @@ -1421,7 +1421,7 @@ Omitting the list of expressions is therefore equivalent to repeating the previous list. The number of identifiers must be equal to the number of expressions in the previous list. Together with the iota constant generator -(§Iota) this mechanism permits light-weight declaration of sequential values: +(§Iota) this mechanism permits light-weight declaration of sequential values:

      @@ -1438,7 +1438,7 @@ const (
       
      -

      Iota

      +

      Iota

      Within a constant declaration, the predeclared pseudo-constant @@ -1490,7 +1490,7 @@ last non-empty expression list.

      -

      Type declarations

      +

      Type declarations

      A type declaration binds an identifier, the type name, @@ -1523,7 +1523,7 @@ type Comparable interface { } -

      Variable declarations

      +

      Variable declarations

      A variable declaration creates a variable, binds an identifier to it and @@ -1551,7 +1551,7 @@ If there are expressions, their number must be equal to the number of identifiers, and the nth variable is initialized to the value of the nth expression. Otherwise, each variable is initialized to the zero -of the type (§The zero value). +of the type (§The zero value). The expressions can be general expressions; they need not be constants.

      @@ -1573,7 +1573,7 @@ var i = 0 // i has type int var f = 3.1415 // f has type float -

      Short variable declarations

      +

      Short variable declarations

      A short variable declaration uses the syntax @@ -1595,7 +1595,7 @@ ch := make(chan int);

      Unlike regular variable declarations, short variable declarations -can be used, by analogy with tuple assignment (§Assignments), to +can be used, by analogy with tuple assignment (§Assignments), to receive the individual elements of a multi-valued expression such as a call to a multi-valued function. In this form, the ExpressionList must be a single such multi-valued expression, the number of @@ -1625,13 +1625,13 @@ field2, offset := nextField(str, offset); // redeclares offset Short variable declarations may appear only inside functions. In some contexts such as the initializers for if, for, or switch statements, -they can be used to declare local temporary variables (§Statements). +they can be used to declare local temporary variables (§Statements).

      -

      Function declarations

      +

      Function declarations

      -A function declaration binds an identifier to a function (§Function types). +A function declaration binds an identifier to a function (§Function types).

      @@ -1655,7 +1655,7 @@ func min(x int, y int) int {
       func flushICache(begin, end uintptr)  // implemented externally
       
      -

      Method declarations

      +

      Method declarations

      A method declaration binds an identifier to a method, @@ -1674,7 +1674,7 @@ The base type must not be a pointer or interface type and must be declared in the same source file as the method. The method is said to be bound to the base type and is visible only within selectors for that type -(§Type declarations, §Selectors). +(§Type declarations, §Selectors).

      @@ -1717,7 +1717,7 @@ However, a function declared this way is not a method.

      -

      Expressions

      +

      Expressions

      An expression specifies the computation of a value by applying @@ -1725,7 +1725,7 @@ operators and functions to operands. An expression has a value and a type.

      -

      Operands

      +

      Operands

      Operands denote the elementary values in an expression. @@ -1736,18 +1736,18 @@ BasicLit = int_lit | float_lit | char_lit | StringLit . -

      Constants

      +

      Constants

      A constant is a literal of a basic type (including the predeclared constants true, false and nil and values denoted by iota) -or a constant expression (§Constant expressions). +or a constant expression (§Constant expressions). Constants have values that are known at compile time.

      -

      Qualified identifiers

      +

      Qualified identifiers

      A qualified identifier is an identifier qualified by a package name prefix. @@ -1761,14 +1761,14 @@ PackageName = identifier .

      A qualified identifier accesses an identifier in a separate package. The identifier must be exported by that package, which -means that it must begin with a Unicode upper case letter (§Exported identifiers). +means that it must begin with a Unicode upper case letter (§Exported identifiers).

       Math.Sin
       
      -

      Composite literals

      +

      Composite literals

      Composite literals construct values for structs, arrays, slices, and maps @@ -1857,7 +1857,7 @@ For array and slice literals the following rules apply:

      -Taking the address of a composite literal (§Address operators) +Taking the address of a composite literal (§Address operators) generates a unique pointer to an instance of the literal's value.

      @@ -1934,7 +1934,7 @@ noteFrequency := map[string]float{
       
      -

      Function literals

      +

      Function literals

      A function literal represents an anonymous function. @@ -1966,7 +1966,7 @@ as they are accessible.

      -

      Primary expressions

      +

      Primary expressions

       PrimaryExpr =
      @@ -1999,7 +1999,7 @@ f.p[i].x()
       
      -

      Selectors

      +

      Selectors

      A primary expression of the form @@ -2114,7 +2114,7 @@ TODO: Specify what happens to receivers. -

      Indexes

      +

      Indexes

      A primary expression of the form @@ -2133,8 +2133,8 @@ rules apply:

      For a of type A or *A -where A is an array type (§Array types), -or for a of type S where S is a slice type (§Slice types): +where A is an array type (§Array types), +or for a of type S where S is a slice type (§Slice types):

      • x must be an integer value and 0 <= x < len(a) @@ -2144,7 +2144,7 @@ or for a of type S where S is a slice typ

        For a of type T -where T is a string type (§Strings): +where T is a string type (§Strings):

        • x must be an integer value and 0 <= x < len(a) @@ -2155,7 +2155,7 @@ where T is a string type (§Strings):

          For a of type M -where M is a map type (§Map types): +where M is a map type (§Map types):

          • x's type must be compatible with the key type of M @@ -2185,10 +2185,10 @@ the result of the index expression is a pair of values with types If the key is present in the map, the expression returns the pair (a[x], true); otherwise it returns (Z, false) where Z is -the zero value for V (§The zero value). +the zero value for V (§The zero value). No run-time exception occurs in this case. The index expression in this construct thus acts like a function call -returning a value and a boolean indicating success. (§Assignments) +returning a value and a boolean indicating success. (§Assignments)

            @@ -2206,7 +2206,7 @@ the entry for key x is deleted from the map; if a regular assignment to an element of the map.

            -

            Slices

            +

            Slices

            Strings, arrays, and slices can be sliced to construct substrings or descriptors @@ -2237,12 +2237,12 @@ For arrays or strings, the indexes for slices, the upper bound is the capacity rather than the length.

            If the sliced operand is a string, the result of the slice operation is another, new -string (§Strings). If the sliced operand is an array or slice, the result -of the slice operation is a slice (§Slice types). +string (§Strings). If the sliced operand is an array or slice, the result +of the slice operation is a slice (§Slice types).

            -

            Type assertions

            +

            Type assertions

            For an expression x and a type T, the primary expression @@ -2261,9 +2261,9 @@ The type of x must be an interface type.

            More precisely, if T is not an interface type, x.(T) asserts that the dynamic type of x is identical to the type T -(§Type identity and compatibility). +(§Type identity and compatibility). If T is an interface type, x.(T) asserts that the dynamic type -of T implements the interface T (§Interface types). +of T implements the interface T (§Interface types).

            If the type assertion holds, the value of the expression is the value @@ -2285,14 +2285,14 @@ v, ok := x.(T) the result of the assertion is a pair of values with types (T, bool). If the assertion holds, the expression returns the pair (x.(T), true); otherwise, the expression returns (Z, false) where Z -is the zero value for type T (§The zero value). +is the zero value for type T (§The zero value). No run-time exception occurs in this case. The type assertion in this construct thus acts like a function call -returning a value and a boolean indicating success. (§Assignments) +returning a value and a boolean indicating success. (§Assignments)

            -

            Calls

            +

            Calls

            Given an expression f of function type @@ -2339,7 +2339,7 @@ p.Scale(3.5) There is no distinct method type and there are no method literals.

            -

            Passing arguments to ... parameters

            +

            Passing arguments to ... parameters

            When a function f has a ... parameter, @@ -2383,7 +2383,7 @@ for a ... in a call to another function with a ... par the parameter is not wrapped again but passed directly. In short, a formal ... parameter is passed unchanged as an actual ... parameter. -

            Operators

            +

            Operators

            Operators combine operands into expressions. @@ -2409,7 +2409,7 @@ The operand types in binary operations must be compatible, with the following ex

            • Except in shift expressions, if one operand has numeric type and the other operand is an ideal number, the ideal number is converted to match the type of - the other operand (§Expressions).
            • + the other operand (§Expressions).
            • Except in shift expressions, if both operands are ideal numbers and one is an ideal float, the other is converted to ideal float @@ -2420,7 +2420,7 @@ The operand types in binary operations must be compatible, with the following ex
            • The right operand in a shift operation must be always be of unsigned integer type or an ideal number that can be safely converted into an unsigned integer type - (§Arithmetic operators).
            • + (§Arithmetic operators).
            • The operands in channel sends differ in type: one is always a channel and the other is a variable or value of the channel's element type.
            • @@ -2470,7 +2470,7 @@ x == y + 1 && <-chan_ptr > 0 -

              Arithmetic operators

              +

              Arithmetic operators

              Arithmetic operators apply to numeric types and yield a result of the same type as the first operand. The four standard arithmetic operators (+, @@ -2572,14 +2572,14 @@ For floating point numbers, while -x is the negation of x.

              -

              Integer overflow

              +

              Integer overflow

              For unsigned integer values, the operations +, -, *, and << are computed modulo 2n, where n is the bit width of the unsigned integer's type -(§Numeric types). Loosely speaking, these unsigned integer operations +(§Numeric types). Loosely speaking, these unsigned integer operations discard high bits upon overflow, and programs may rely on ``wrap around''.

              @@ -2593,7 +2593,7 @@ not occur. For instance, it may not assume that x < x + 1 is alw

              -

              Comparison operators

              +

              Comparison operators

              Comparison operators yield a boolean result. All comparison operators apply @@ -2622,11 +2622,11 @@ Booleans are equal if they are either both "true" or both "false".

              The rules for comparison of composite types are described in the -section on §Comparison compatibility. +section on §Comparison compatibility.

              -

              Logical operators

              +

              Logical operators

              Logical operators apply to boolean operands and yield a boolean result. @@ -2640,7 +2640,7 @@ The right operand is evaluated conditionally. -

              Address operators

              +

              Address operators

              The unary prefix address-of operator & generates the address of its operand, which must be a variable, @@ -2733,7 +2733,7 @@ is equivalent to the function call

              -TODO: should probably describe the effect of (t.m) under §Expressions if t.m +TODO: should probably describe the effect of (t.m) under §Expressions if t.m denotes a method: Effect is as described above, converts into function.

              @@ -2773,10 +2773,10 @@ of a result parameter (e.g.: func f() (x int, p *int) { return 2, &x }).

              -

              Communication operators

              +

              Communication operators

              -The term channel means "variable of channel type" (§Channel types). +The term channel means "variable of channel type" (§Channel types).

              The send operation uses the binary operator "<-", which operates on @@ -2856,7 +2856,7 @@ If the operation can proceeed, the boolean variable and the value stored in x; otherwise ok is set to false and x is set to the -zero value for its type (§The zero value). +zero value for its type (§The zero value).

              @@ -2864,7 +2864,7 @@ zero value for its type (§The zero value). need to be presented regarding send, receive, select, and goroutines.

              -

              Constant expressions

              +

              Constant expressions

              Constant expressions may contain only constants, iota, @@ -2875,7 +2875,7 @@ In practice, constant expressions are those that can be evaluated at compile tim

              The type of a constant expression is determined by the type of its elements. If it contains only numeric literals, its type is ideal -integer or ideal float (§Ideal number). Whether a literal +integer or ideal float (§Ideal number). Whether a literal is an integer or float depends on the syntax of the literals (123 vs. 123.0). The nature of the arithmetic operations within the expression depends, elementwise, on the values; @@ -2949,7 +2949,7 @@ Also it may be possible to make typed constants more like variables, at the cost overflow etc. errors being caught.

              -

              Order of evaluation

              +

              Order of evaluation

              When evaluating the elements of an assignment or expression, @@ -2975,7 +2975,7 @@ of y is not specified.


              -

              Statements

              +

              Statements

              Statements control execution. @@ -3000,12 +3000,12 @@ which may be omitted only if the previous statement:

              • ends with the closing parenthesis ")" of a list of declarations - (§Declarations and Scope); or
              • + (§Declarations and Scope); or
              • ends with a closing brace "}" that is not part of an expression.
              -

              Empty statements

              +

              Empty statements

              The empty statement does nothing. @@ -3021,7 +3021,7 @@ adding an empty statement.

              -

              Labeled statements

              +

              Labeled statements

              A labeled statement may be the target of a goto, @@ -3038,7 +3038,7 @@ Error: log.Fatal("error encountered") -

              Expression statements

              +

              Expression statements

              Function calls, method calls, and channel operations @@ -3056,7 +3056,7 @@ f(x+y) -

              IncDec statements

              +

              IncDec statements

              The "++" and "--" statements increment or decrement their operands @@ -3069,7 +3069,7 @@ IncDecStmt = Expression ( "++" | "--" ) .

              -The following assignment statements (§Assignments) are semantically +The following assignment statements (§Assignments) are semantically equivalent:

              @@ -3079,7 +3079,7 @@ x++ x += 1 x-- x -= 1 -

              Assignments

              +

              Assignments

               Assignment = ExpressionList assign_op ExpressionList .
              @@ -3116,8 +3116,8 @@ a[i] <<= 2
               A tuple assignment assigns the individual elements of a multi-valued
               operation to a list of variables.  There are two forms.  In the
               first, the right hand operand is a single multi-valued expression
              -such as a function evaluation or channel or map operation (§Channel
              -operations, §Map operations) or a type assertion (§Type assertions).
              +such as a function evaluation or channel or map operation (§Channel
              +operations, §Map operations) or a type assertion (§Type assertions).
               The number of operands on the left
               hand side must match the number of values.  For instance, If
               f is a function returning two values,
              @@ -3145,12 +3145,12 @@ a, b = b, a  // exchange a and b
               
               

              In assignments, the type of each value must be assignment compatible -(§Assignment compatibility) with the type of the +(§Assignment compatibility) with the type of the operand to which it is assigned.

              -

              If statements

              +

              If statements

              "If" statements specify the conditional execution of two branches @@ -3186,7 +3186,7 @@ if x := f(); x < y {

              -

              Switch statements

              +

              Switch statements

              "Switch" statements provide multi-way execution. @@ -3207,7 +3207,7 @@ In a type switch, the cases contain types that are compared against the type of a specially annotated switch expression.

              -

              Expression switches

              +

              Expression switches

              In an expression switch, @@ -3234,7 +3234,7 @@ ExprSwitchCase = "case" ExpressionList | "default" .

              In a case or default clause, the last statement only may be a "fallthrough" statement -(§Fallthrough statement) to +(§Fallthrough statement) to indicate that control should flow from the end of this clause to the first statement of the next clause. Otherwise control flows to the end of the "switch" statement. @@ -3264,13 +3264,13 @@ case x == 4: f3(); } -

              Type switches

              +

              Type switches

              A type switch compares types rather than values. It is otherwise similar to an expression switch. It is introduced by special notation in the form of a simple declaration whose right hand side -has the form of a type assertion (§Type assertions) +has the form of a type assertion (§Type assertions) using the reserved word type rather than an actual type. Cases then match literal types against the dynamic type of the expression in the type assertion. @@ -3286,7 +3286,7 @@ TypeSwitchCase = "case" Type | "default" .

              As a special case, the type in the type switch case may be an identifier denoting the predeclared constant nil -(§Predeclared identifiers). +(§Predeclared identifiers). If the interface value equals nil, only an explict nil case or "default" case will execute. @@ -3343,7 +3343,7 @@ The type switch guard may be preceded by a simple statement, which executes before the guard is evaluated.

              -

              For statements

              +

              For statements

              A "for" statement specifies repeated execution of a block. The iteration is @@ -3450,7 +3450,7 @@ it does not process the zero value sent before the channel is closed.

              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 int and the array element type, or the map key and value types, respectively. If the iteration variables are declared outside the "for" statement, @@ -3483,7 +3483,7 @@ they will not be processed. If map entries are inserted during iteration, the behavior is implementation-dependent, but each entry will be processed at most once.

              -

              Go statements

              +

              Go statements

              A "go" statement starts the execution of a function or method call @@ -3507,7 +3507,7 @@ go func(ch chan <- bool) { for { sleep(10); ch <- true; }} (c) -

              Select statements

              +

              Select statements

              A "select" statement chooses which of a set of possible communications @@ -3547,7 +3547,7 @@ If multiple cases can proceed, a uniform fair choice is made to decide which single communication will execute.

              The receive case may declare a new variable using a short variable declaration -(§Short variable declarations). +(§Short variable declarations).

              @@ -3575,7 +3575,7 @@ TODO: Make semantics more precise.
               
               
               
              -

              Return statements

              +

              Return statements

              A "return" statement terminates execution of the containing function @@ -3629,9 +3629,9 @@ func complex_f2() (re float, im float) {

            • The expression list may be empty if the functions's result - type specifies names for its result parameters (§Function Types). + type specifies names for its result parameters (§Function Types). The result parameters act as ordinary local variables that are - initialized to the zero values for their type (§The zero value) + initialized to the zero values for their type (§The zero value) and the function may assign values to them as necessary. The "return" statement returns the values of these variables.
              @@ -3652,7 +3652,7 @@ TODO: Language about result parameters needs to go into a section on
               
               

              -

              Break statements

              +

              Break statements

              A "break" statement terminates execution of the innermost @@ -3667,7 +3667,7 @@ BreakStmt = "break" [ Label ]. If there is a label, it must be that of an enclosing "for", "switch" or "select" statement, and that is the one whose execution terminates -(§For statements, §Switch statements, §Select statements). +(§For statements, §Switch statements, §Select statements).

              @@ -3678,11 +3678,11 @@ L: for i < n {
               }
               
              -

              Continue statements

              +

              Continue statements

              A "continue" statement begins the next iteration of the -innermost "for" loop at the post statement (§For statements). +innermost "for" loop at the post statement (§For statements).

              @@ -3693,7 +3693,7 @@ ContinueStmt = "continue" [ Label ].
               The optional label is analogous to that of a "break" statement.
               

              -

              Goto statements

              +

              Goto statements

              A "goto" statement transfers control to the statement with the corresponding label. @@ -3725,11 +3725,11 @@ the creation of v. (TODO: Eliminate in favor of used and not set errors?)

              -

              Fallthrough statements

              +

              Fallthrough statements

              A "fallthrough" statement transfers control to the first statement of the -next case clause in a expression "switch" statement (§Expression switches). It may +next case clause in a expression "switch" statement (§Expression switches). It may be used only as the final non-empty statement in a case or default clause in an expression "switch" statement.

              @@ -3739,7 +3739,7 @@ FallthroughStmt = "fallthrough" .
              -

              Defer statements

              +

              Defer statements

              A "defer" statement invokes a function whose execution is deferred to the moment @@ -3772,7 +3772,7 @@ for i := 0; i <= 3; i++ {


              -

              Predeclared functions

              +

              Predeclared functions

              • cap
              • close @@ -3786,7 +3786,7 @@ for i := 0; i <= 3; i++ {
              • println
              -

              Length and capacity

              +

              Length and capacity

               Call       Argument type       Result
              @@ -3816,7 +3816,7 @@ space allocated in the underlying array (for a slice) or map. For a slice
               
              -

              Conversions

              +

              Conversions

              Conversions look like function calls of the form @@ -3842,7 +3842,7 @@ to a variable of type T.

            • 2) The conversion succeeds if the value would be assignment-compatible to a variable of type T if the value type or T or any of their component -types are unnamed (§Type identity and compatibility). +types are unnamed (§Type identity and compatibility).
            • 3) Between integer types. If the value is a signed quantity, it is @@ -3893,17 +3893,17 @@ string([]byte{'h', 'e', 'l', 'l', 'o'}) // "hello" There is no linguistic mechanism to convert between pointers and integers. The unsafe package implements this functionality under -restricted circumstances (§Package unsafe). +restricted circumstances (§Package unsafe).

              -

              Allocation

              +

              Allocation

              The built-in function new takes a type T and returns a value of type *T. The memory is initialized as described in the section on initial values -(§The zero value). +(§The zero value).

              @@ -3926,7 +3926,7 @@ and returns a value of type *S containing the address
               of the memory.
               

              -

              Making slices, maps and channels

              +

              Making slices, maps and channels

              Slices, maps and channels are reference types that do not require the @@ -3936,7 +3936,7 @@ which must be a slice, map or channel type, optionally followed by a type-specific list of expressions. It returns a value of type T (not *T). The memory is initialized as described in the section on initial values -(§The zero value). +(§The zero value).

              @@ -3969,7 +3969,7 @@ m := make(map[string] int, 100);  # map with initial space for 100 elements
               
               
              -

              Packages

              +

              Packages

              Go programs are constructed by linking together packages. @@ -3979,7 +3979,7 @@ and variables. Those elements may be imported and used in another package.

              -

              Source file organization

              +

              Source file organization

              Each source file consists of a package clause defining the package @@ -3993,7 +3993,7 @@ types, variables, and constants. SourceFile = PackageClause { ImportDecl [ ";" ] } { TopLevelDecl [ ";" ] } .

              -

              Package clause

              +

              Package clause

              A package clause begins each source file and defines the package @@ -4013,10 +4013,10 @@ A set of files sharing the same PackageName form the implementation of a package An implementation may require that all source files for a package inhabit the same directory.

              -

              Import declarations

              +

              Import declarations

              -A source file gains access to exported identifiers (§Exported +A source file gains access to exported identifiers (§Exported identifiers) from another package through an import declaration. In the general form, an import declaration provides an identifier that code in the source file may use to access the imported package's @@ -4035,7 +4035,7 @@ PackageFileName = StringLit .

              After an import, in the usual case an exported name N from the imported package P may be accessed by the qualified identifier -P.N (§Qualified identifiers). The actual +P.N (§Qualified identifiers). The actual name P depends on the form of the import declaration. If an explicit package name p1 is provided, the qualified identifer will have the form p1.N. If no name @@ -4061,7 +4061,7 @@ import "lib/math" math.Sin import . "lib/math" Sin

              -

              Multiple-file packages

              +

              Multiple-file packages

              If a package is constructed from multiple source files, @@ -4086,7 +4086,7 @@ then a second file math2.go also in may refer directly to Sin and twoPi.

              -

              An example package

              +

              An example package

              Here is a complete Go package that implements a concurrent prime sieve. @@ -4134,9 +4134,9 @@ func main() {


              -

              Program initialization and execution

              +

              Program initialization and execution

              -

              The zero value

              +

              The zero value

              When memory is allocated to store a value, either through a declaration or new(), and no explicit initialization is provided, the memory is @@ -4183,7 +4183,7 @@ The same would also be true after var t T

            • -

              Program execution

              +

              Program execution

              A package with no imports is initialized by assigning initial values to all its package-level variables in declaration order and then calling any @@ -4245,9 +4245,9 @@ is not imported by any other package.


              -

              System considerations

              +

              System considerations

              -

              Package unsafe

              +

              Package unsafe

              The built-in package unsafe, known to the compiler, @@ -4279,7 +4279,7 @@ The function Sizeof takes an expression denoting a variable of any type and returns the size of the variable in bytes.

              -The function Offsetof takes a selector (§Selectors) denoting a struct +The function Offsetof takes a selector (§Selectors) denoting a struct field of any type and returns the field offset in bytes relative to the struct's address. For a struct s with field f:

              @@ -4310,9 +4310,9 @@ Calls to Alignof, Offsetof, and

              -

              Size and alignment guarantees

              +

              Size and alignment guarantees

              -For the numeric types (§Numeric types), the following sizes are guaranteed: +For the numeric types (§Numeric types), the following sizes are guaranteed:
               type                      size in bytes
              @@ -4341,7 +4341,7 @@ The following minimal alignment properties are guaranteed:
               
               
              -

              Differences between this doc and implementation - TODO

              +

              Implementation differences - TODO

              Implementation does not honor the restriction on goto statements and targets (no intervening declarations). -- 2.48.1