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)-1Indexes).

@@ -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)-1Indexes). 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 floatIdeal 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):