diff --git a/doc/go_spec.html b/doc/go_spec.html index d602168c672..d783a2e0afd 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -36,7 +36,7 @@ href="/">the Go home page.

Go is a general-purpose language designed with systems programming -in mind. It is strongly typed and garbage-collected, and has explicit +in mind. It is strongly typed and garbage-collected and has explicit support for concurrent programming. Programs are constructed from packages, whose properties allow efficient management of dependencies. The existing implementations use a traditional @@ -77,7 +77,7 @@ operators, in increasing precedence:

Lower-case production names are used to identify lexical tokens. Non-terminals are in CamelCase. Lexical symbols are enclosed in -double "" or back quotes ``. +double quotes "" or back quotes ``.

@@ -112,7 +112,13 @@ unicode_letter = /* a Unicode code point classified as "Letter" */ . unicode_digit = /* a Unicode code point classified as "Digit" */ . -(The Unicode Standard, Section 4.5 General Category - Normative.) +

+In The Unicode Standard 5.0, +Section 4.5 General Category-Normative +defines a set of character categories. Go treats +those characters in category Lu, Ll, Lt, Lm, or Lo as Unicode letters, +and those in category Nd as Unicode digits. +

Letters and digits

@@ -259,8 +265,9 @@ the destination must be able to represent the assigned value.

Implementation restriction: A compiler may implement ideal numbers -by choosing an internal representation with at least twice the precision -of any machine type. +by choosing an internal representation with at least twice as many +bits as any machine type; for floats, both the mantissa and exponent +must be twice as large.

Character literals

@@ -295,8 +302,8 @@ the digits in the corresponding base.

Although these representations all result in an integer, they have different valid ranges. Octal escapes must represent a value between -0 and 255 inclusive. (Hexadecimal escapes satisfy this condition -by construction). The `Unicode' escapes \u and \U +0 and 255 inclusive. Hexadecimal escapes satisfy this condition +by construction. The escapes \u and \U represent Unicode code points so within them some values are illegal, in particular those above 0x10FFFF and surrogate halves.

@@ -427,6 +434,14 @@ literal.


+

Boolean literals

+ +

+A boolean literal is one of the predeclared constants +true or false. The value of a boolean +literal is an ideal bool. +

+

Types

@@ -545,11 +560,11 @@ 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 -illegal to take the address of such an element, that is, even if -s[i] is the ith byte of a +illegal to take the address of such an element; if +s[i] is the ith byte of a string, &s[i] is invalid. The length of string s can be discovered using the built-in function -len(s). It is a compile-time constant if s +len(s). The length is a compile-time constant if s is a string literal.

@@ -642,7 +657,7 @@ make([]T, length, capacity)

The make() call allocates a new, hidden array to which the returned -slice value refers. That is, calling make +slice value refers. That is, executing

@@ -710,8 +725,8 @@ struct {
 

-The unqualified type name of an anonymous field must not conflict with the -field identifier (or unqualified type name for an anonymous field) of any +The unqualified type name of an anonymous field must be distinct from the +field identifier (or unqualified type name for an anonymous field) of every other field within the struct. The following declaration is illegal:

@@ -749,17 +764,17 @@ a type named T: A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the identifiers in the corresponding field declaration. The tags are made -visible through a reflection library (TODO: reference?) +visible through a reflection library TODO: reference? but are otherwise ignored.

-// A struct corresponding to the EventIdMessage protocol buffer.
+// A struct corresponding to the TimeStamp protocol buffer.
 // The tag strings define the protocol buffer field numbers.
 struct {
-	time_usec uint64 "field 1";
-	server_ip uint32 "field 2";
-	process_id uint32 "field 3";
+	microsec  uint64 "field 1";
+	serverIP6 uint64 "field 2";
+	process   string "field 3";
 }
 
@@ -810,8 +825,7 @@ one unnamed result that is not a function type it may writen as an unparenthesiz For the last parameter only, instead of a type one may write ... to indicate that the function may be invoked with zero or more additional arguments of any -type. If parameters of such a function are named, the final identifier -list must be a single name, that of the ... parameter. +type.

@@ -961,11 +975,11 @@ map [string] interface {}
 The number of elements is called the length and is never negative.
 The length of a map m can be discovered using the
 built-in function len(m) and may change during execution.
-The value of an uninitialized map is nil.
+Values may be added and removed
+during execution using special forms of assignment.
 

-Upon creation, a map is empty. Values may be added and removed -during execution using special forms of assignment (§Assignments). +The value of an uninitialized map is nil. 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: @@ -1024,7 +1038,7 @@ make(chan int, 100)

The capacity, in number of elements, sets the size of the buffer in the channel. If the -capacity is greater than zero, the channel is asynchronous and, provided the +capacity is greater than zero, the channel is asynchronous: provided the buffer is not full, sends can succeed without blocking. If the capacity is zero or absent, the communication succeeds only when both a sender and receiver are ready.

@@ -1073,7 +1087,7 @@ identical types. In detail:
  • Two function types are identical if they have the same number of parameters and result values and if corresponding parameter and result types are - identical. All "..." parameters have identical type. + identical. All "..." parameters are defined to have identical type. Parameter and result names are not required to match.
  • Two interface types are identical if they have the same set of methods @@ -1103,11 +1117,11 @@ Given the declarations
     type (
     	T0 []string;
    -	T1 []string
    +	T1 []string;
     	T2 struct { a, b int };
     	T3 struct { a, c int };
    -	T4 func (int, float) *T0
    -	T5 func (x int, y float) *[]string
    +	T4 func (int, float) *T0;
    +	T5 func (x int, y float) *[]string;
     )
     
    @@ -1177,9 +1191,10 @@ A value can always be assigned to the blank identifi

    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; +Except as noted, 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; booleans may be compared only for equality or inequality.

    @@ -1195,15 +1210,13 @@ Arrays and structs may not be compared to anything.
  • A slice value may only be compared explicitly against nil. A slice value is equal to nil if it has been assigned the explicit -value nil or if it is a variable (or array element, -field, etc.) that has not been modified since it was created -uninitialized. +value nil, if it is uninitialized, or if it has +been assigned another slice value equal to nil·
  • Similarly, an interface value is equal to nil if it has -been assigned the explicit value nil or if it is a -variable (or array element, field, etc.) that has not been modified -since it was created uninitialized. +been assigned the explicit value nil, if it is uninitialized, +or if it has been assigned another interface value equal to nil.
  • For types that can be compared to nil, @@ -1369,7 +1382,7 @@ is exported if both:

    1. the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and -
    2. the identifier is declared in the package block or is a field or method of a type +
    3. the identifier is declared in the package block or denotes a field or method of a type declared in that block.

    @@ -1408,7 +1421,8 @@ ExpressionList = Expression { "," Expression } .

    If the type is omitted, the constants take the individual types of the corresponding expressions, which may be -an ideal number or ideal string. +an ideal number, ideal string, +or ideal bool. 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. @@ -1429,7 +1443,7 @@ const u, v float = 0, 3 // u = 0.0, v = 3.0 Within a parenthesized const declaration list the expression list may be omitted from any but the first declaration. Such an empty list is equivalent to the textual substitution of the -first preceding non-empty expression list, and its type if any. +first preceding non-empty expression list and its type if any. 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. @@ -1530,8 +1544,10 @@ type TreeNode struct { value *Comparable; } -type Comparable interface { - cmp(Comparable) int +type Cipher interface { + BlockSize() int; + Encrypt(src, dst []byte); + Decrypt(src, dst []byte); }

  • @@ -1551,7 +1567,7 @@ VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList var i int var U, V, W float var k = 0 -var x, y float = -1.0, -2.0 +var x, y float = -1, -2 var ( i int; u, v, s = 2.0, 3.0, "bar" @@ -1562,7 +1578,8 @@ var _, found = entries[name]; // map lookup; only interested in "found"

    If a list of expressions is given, the variables are initialized -by assigning those expressions to the variables (§Assignments). +by assigning the expressions to the variables (§Assignments) +in order; all expressions must be consumed and all variables initialized from them. Otherwise, each variable is initialized to its zero value.

    @@ -1574,15 +1591,16 @@ of the expression list.

    If the type is absent and the corresponding expression is a constant -expression of ideal integer, float, or string type, the type of the +expression of ideal integer, float, string or bool type, the type of the declared variable is int, float, -or string respectively: +string, or bool respectively:

     var i = 0       // i has type int
     var f = 3.1415  // f has type float
     var s = "OMDB"  // s has type string
    +var t = true    // t has type bool
     

    Short variable declarations

    @@ -1605,7 +1623,7 @@ 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" +_, y, _ := coord(p); // coord() returns three values; only interested in y coordinate

    @@ -1694,7 +1712,8 @@ func (p *Point) Scale(factor float) {

    -bind the methods Length and Scale +bind the methods Length and Scale, +with receiver type *Point, to the base type Point.

    @@ -1765,7 +1784,7 @@ package, which means that it must begin with a Unicode upper case letter.

    -Math.Sin
    +math.Sin
     

    @@ -1788,7 +1807,9 @@ LiteralType = StructType | ArrayType | "[" "..." "]" ElementType | SliceType | MapType | TypeName . ElementList = Element { "," Element } [ "," ] . Element = [ Key ":" ] Value . -Key = Expression . +Key = FieldName | Index . +FieldName = identifier . +Index = Expression . Value = Expression . @@ -1800,7 +1821,7 @@ The types of the expressions must be assignm the respective field, element, and key types of the LiteralType; there is no additional conversion. The key is interpreted as a field name for struct literals, -an index for array and slice literals, and a key for map literals. +an index expression for array and slice literals, and a key for map literals. For map literals, all elements must have a key. It is an error to specify multiple elements with the same field name or constant key value. @@ -1810,13 +1831,13 @@ constant key value. For struct literals the following rules apply: