From da38974c8851c06868c8d941db5aa6d44e023524 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 2 Mar 2009 19:13:40 -0800 Subject: [PATCH] address most of the editorial comments through "types" R=rsc DELTA=41 (9 added, 4 deleted, 28 changed) OCL=25611 CL=25611 --- doc/go_spec.html | 61 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 6e69ece519f..dade367047d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -188,10 +188,6 @@ The form "a ... b" represents the set of characters from a through b as alternatives.

-

-Where possible, recursive productions are used to express evaluation order -and operator precedence syntactically. -


Source code representation

@@ -621,8 +617,9 @@ uintptr smallest uint type large enough to store the uninterpreted

-Except for byte, which is an alias for uint8, -to avoid portability issues all numeric types are distinct. Conversions +To avoid portability issues all numeric types are distinct except +byte, which is an alias for uint8. +Conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a @@ -669,7 +666,7 @@ StringLit = string_lit { string_lit } .

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 +an identifier and type for each field. Within a struct, field identifiers must be unique and field types must be complete (§Types).

@@ -696,8 +693,8 @@ struct {

A field declared with a type but no field identifier is an anonymous field. Such a field type must be specified as -a type name T or as a pointer to a type name *T -and T itself may not be +a type name T or as a pointer to a type name *T, +and T itself, may not be a pointer or interface type. The unqualified type name acts as the field identifier.

@@ -706,8 +703,8 @@ a pointer or interface type. The unqualified type name acts as the field identif struct { T1; // the field name is T1 *T2; // the field name is T2 - P.T3; // the field name is the unqualified type name T3 - *P.T4; // the field name is the unqualified type name T4 + P.T3; // the field name is T3 + *P.T4; // the field name is T4 x, y int; } @@ -782,7 +779,7 @@ indices 0 through the len(a)-1 (§Indexes).

A pointer type denotes the set of all pointers to variables of a given -type, called the ``base type'' of the pointer. +type, called the base type of the pointer. A pointer value may be nil.

@@ -826,7 +823,7 @@ The types of parameters and results must be complete.

For the last parameter only, instead of a type one may write ... to indicate that the function may be invoked with -an arbitrary number (including zero) of additional arguments of any +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.

@@ -995,7 +992,8 @@ and the relationship between len() and cap() is:

-The value of an uninitialized slice is nil, and its length and capacity +The value of an uninitialized slice is nil. +The length and capacity of a nil slice are 0. A new, initialized slice value for a given element type T is made using the built-in function make, which takes a slice type and parameters specifying the length and optionally the capacity: @@ -1020,7 +1018,7 @@ produces the same slice as allocating an array and slicing it:

-make([capacity]T)[0 : length]
+make([]T, capacity)[0 : length]
 
@@ -1062,20 +1060,27 @@ 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 +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). A new, empty map value is made using the built-in function make, which takes the map type and an optional -capacity, an allocation hint, as arguments: +capacity hint as arguments:

-make(map[string] int, 100);
+make(map[string] int)
+make(map[string] int, 100)
 
+

+The initial capacity does not bound its size: +maps grow to accommodate the number of items +stored in them. +

+

Channel types

@@ -1113,7 +1118,7 @@ which takes the channel type and an optional capacity as arguments:

-make(chan int, 100);
+make(chan int, 100)
 

@@ -1130,7 +1135,7 @@ Types may be different, structurally equal (or just equal), or identical. Go is type safe: different types cannot be mixed in binary operations and values cannot be assigned to variables of different -types. They can be assigned to variables of equal type. +types. Values can be assigned to variables of equal type.

Type equality and identity

@@ -1245,7 +1250,7 @@ When assigning to a slice variable, the array is not copied but a slice comprising the entire array is created.
  • -A value can be assigned to an interface variable if the dynamic +A value can be assigned to an interface variable if the static type of the value implements the interface.
  • @@ -1273,8 +1278,8 @@ compared for equality or inequality using the == and Arrays and structs may not be compared to anything.
  • -A slice value may only be compared explicitly against nil -and is equal to nil if it has been assigned the explicit +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. @@ -1294,15 +1299,15 @@ unequal if one equals nil and one does not. Pointer values are equal if they point to the same location.
  • -Function values are equal if they point to the same function. +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 of make +Channel and map values are equal if they were created by the same call to make (§Making slices, maps, and channels).
  • -Interface values are comparison compatible if they have the same static type and -equal if they have the same dynamic type. +Interface values may be compared if they have the same static type. +They will be equal only if they have the same dynamic type and the underlying values are equal.

  • @@ -1437,7 +1442,7 @@ CompleteType = Type .

    If the type (CompleteType) 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.