From da38974c8851c06868c8d941db5aa6d44e023524 Mon Sep 17 00:00:00 2001
From: Rob Pike "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. -
-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.
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
.
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.
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. +
+@@ -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.
==
and
Arrays and structs may not be compared to anything.
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.
make
+Channel and map values are equal if they were created by the same call to make
(§Making slices, maps, and channels).
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.