mirror of
https://github.com/golang/go
synced 2024-11-22 00:04:41 -07:00
address most of the editorial comments through "types"
R=rsc DELTA=41 (9 added, 4 deleted, 28 changed) OCL=25611 CL=25611
This commit is contained in:
parent
ea3d4540b3
commit
da38974c88
@ -188,10 +188,6 @@ The form <code>"a ... b"</code> represents the set of characters from
|
|||||||
<code>a</code> through <code>b</code> as alternatives.
|
<code>a</code> through <code>b</code> as alternatives.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
|
||||||
Where possible, recursive productions are used to express evaluation order
|
|
||||||
and operator precedence syntactically.
|
|
||||||
</p>
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<h2>Source code representation</h2>
|
<h2>Source code representation</h2>
|
||||||
@ -621,8 +617,9 @@ uintptr smallest uint type large enough to store the uninterpreted
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Except for <code>byte</code>, which is an alias for <code>uint8</code>,
|
To avoid portability issues all numeric types are distinct except
|
||||||
to avoid portability issues all numeric types are distinct. Conversions
|
<code>byte</code>, which is an alias for <code>uint8</code>.
|
||||||
|
Conversions
|
||||||
are required when different numeric types are mixed in an expression
|
are required when different numeric types are mixed in an expression
|
||||||
or assignment. For instance, <code>int32</code> and <code>int</code>
|
or assignment. For instance, <code>int32</code> and <code>int</code>
|
||||||
are not the same type even though they may have the same size on a
|
are not the same type even though they may have the same size on a
|
||||||
@ -669,7 +666,7 @@ StringLit = string_lit { string_lit } .
|
|||||||
<p>
|
<p>
|
||||||
A struct is a sequence of named
|
A struct is a sequence of named
|
||||||
elements, called fields, with various types. A struct type declares
|
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).
|
must be unique and field types must be complete (§Types).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -696,8 +693,8 @@ struct {
|
|||||||
<p>
|
<p>
|
||||||
A field declared with a type but no field identifier is an <i>anonymous field</i>.
|
A field declared with a type but no field identifier is an <i>anonymous field</i>.
|
||||||
Such a field type must be specified as
|
Such a field type must be specified as
|
||||||
a type name <code>T</code> or as a pointer to a type name <code>*T</code>
|
a type name <code>T</code> or as a pointer to a type name <code>*T</code>,
|
||||||
and <code>T</code> itself may not be
|
and <code>T</code> itself, may not be
|
||||||
a pointer or interface type. The unqualified type name acts as the field identifier.
|
a pointer or interface type. The unqualified type name acts as the field identifier.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -706,8 +703,8 @@ a pointer or interface type. The unqualified type name acts as the field identif
|
|||||||
struct {
|
struct {
|
||||||
T1; // the field name is T1
|
T1; // the field name is T1
|
||||||
*T2; // the field name is T2
|
*T2; // the field name is T2
|
||||||
P.T3; // the field name is the unqualified type name T3
|
P.T3; // the field name is T3
|
||||||
*P.T4; // the field name is the unqualified type name T4
|
*P.T4; // the field name is T4
|
||||||
x, y int;
|
x, y int;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
@ -782,7 +779,7 @@ indices 0 through the <code>len(a)-1</code> (§Indexes).
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
A pointer type denotes the set of all pointers to variables of a given
|
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 <i>base type</i> of the pointer.
|
||||||
A pointer value may be <code>nil</code>.
|
A pointer value may be <code>nil</code>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@ -826,7 +823,7 @@ The types of parameters and results must be complete.
|
|||||||
<p>
|
<p>
|
||||||
For the last parameter only, instead of a type one may write
|
For the last parameter only, instead of a type one may write
|
||||||
<code>...</code> to indicate that the function may be invoked with
|
<code>...</code> 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
|
type. If parameters of such a function are named, the final identifier
|
||||||
list must be a single name, that of the <code>...</code> parameter.
|
list must be a single name, that of the <code>...</code> parameter.
|
||||||
</p>
|
</p>
|
||||||
@ -995,7 +992,8 @@ and the relationship between <code>len()</code> and <code>cap()</code> is:
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The value of an uninitialized slice is <code>nil</code>, and its length and capacity
|
The value of an uninitialized slice is <code>nil</code>.
|
||||||
|
The length and capacity of a <code>nil</code> slice
|
||||||
are 0. A new, initialized slice value for a given element type <code>T</code> is
|
are 0. A new, initialized slice value for a given element type <code>T</code> is
|
||||||
made using the built-in function <code>make</code>, which takes a slice type
|
made using the built-in function <code>make</code>, which takes a slice type
|
||||||
and parameters specifying the length and optionally the capacity:
|
and parameters specifying the length and optionally the capacity:
|
||||||
@ -1020,7 +1018,7 @@ produces the same slice as allocating an array and slicing it:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
make([capacity]T)[0 : length]
|
make([]T, capacity)[0 : length]
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
@ -1062,20 +1060,27 @@ map [string] interface {}
|
|||||||
The number of elements is called the length and is never negative.
|
The number of elements is called the length and is never negative.
|
||||||
The length of a map <code>m</code> can be discovered using the
|
The length of a map <code>m</code> can be discovered using the
|
||||||
built-in function <code>len(m)</code> and may change during execution.
|
built-in function <code>len(m)</code> and may change during execution.
|
||||||
The value of an uninitialized map is <code>nil</code>
|
The value of an uninitialized map is <code>nil</code>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Upon creation, a map is empty. Values may be added and removed
|
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
|
A new, empty map value is made using the built-in
|
||||||
function <code>make</code>, which takes the map type and an optional
|
function <code>make</code>, which takes the map type and an optional
|
||||||
capacity, an allocation hint, as arguments:
|
capacity hint as arguments:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
make(map[string] int, 100);
|
make(map[string] int)
|
||||||
|
make(map[string] int, 100)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The initial capacity does not bound its size:
|
||||||
|
maps grow to accommodate the number of items
|
||||||
|
stored in them.
|
||||||
|
</p>
|
||||||
|
|
||||||
<h3>Channel types</h3>
|
<h3>Channel types</h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -1113,7 +1118,7 @@ which takes the channel type and an optional capacity as arguments:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
make(chan int, 100);
|
make(chan int, 100)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -1130,7 +1135,7 @@ Types may be <i>different</i>, <i>structurally equal</i> (or just <i>equal</i>),
|
|||||||
or <i>identical</i>.
|
or <i>identical</i>.
|
||||||
Go is <i>type safe</i>: different types cannot be mixed
|
Go is <i>type safe</i>: different types cannot be mixed
|
||||||
in binary operations and values cannot be assigned to variables of different
|
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.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>Type equality and identity </h3>
|
<h3>Type equality and identity </h3>
|
||||||
@ -1245,7 +1250,7 @@ When assigning to a slice variable, the array is not copied but a
|
|||||||
slice comprising the entire array is created.
|
slice comprising the entire array is created.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
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.
|
type of the value implements the interface.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@ -1273,8 +1278,8 @@ compared for equality or inequality using the <code>==</code> and
|
|||||||
Arrays and structs may not be compared to anything.
|
Arrays and structs may not be compared to anything.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
A slice value may only be compared explicitly against <code>nil</code>
|
A slice value may only be compared explicitly against <code>nil</code>.
|
||||||
and is equal to <code>nil</code> if it has been assigned the explicit
|
A slice value is equal to <code>nil</code> if it has been assigned the explicit
|
||||||
value <code>nil</code> or if it is a variable (or array element,
|
value <code>nil</code> or if it is a variable (or array element,
|
||||||
field, etc.) that has not been modified since it was created
|
field, etc.) that has not been modified since it was created
|
||||||
uninitialized.
|
uninitialized.
|
||||||
@ -1294,15 +1299,15 @@ unequal if one equals <code>nil</code> and one does not.
|
|||||||
Pointer values are equal if they point to the same location.
|
Pointer values are equal if they point to the same location.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Function values are equal if they point to the same function.
|
Function values are equal if they refer to the same function.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Channel and map values are equal if they were created by the same call of <code>make</code>
|
Channel and map values are equal if they were created by the same call to <code>make</code>
|
||||||
(§Making slices, maps, and channels).
|
(§Making slices, maps, and channels).
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Interface values are comparison compatible if they have the same static type and
|
Interface values may be compared if they have the same static type.
|
||||||
equal if they have the same dynamic type.
|
They will be equal only if they have the same dynamic type and the underlying values are equal.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<hr/>
|
<hr/>
|
||||||
@ -1437,7 +1442,7 @@ CompleteType = Type .
|
|||||||
<p>
|
<p>
|
||||||
If the type (CompleteType) is omitted, the constants take the
|
If the type (CompleteType) is omitted, the constants take the
|
||||||
individual types of the corresponding expressions, which may be
|
individual types of the corresponding expressions, which may be
|
||||||
``ideal integer'' or ``ideal float'' (§Ideal number). If the type
|
<i>ideal integer</i> or <i>ideal float</i> (§Ideal number). If the type
|
||||||
is present, all constants take the type specified, and the types
|
is present, all constants take the type specified, and the types
|
||||||
of all the expressions must be assignment-compatible
|
of all the expressions must be assignment-compatible
|
||||||
with that type.
|
with that type.
|
||||||
|
Loading…
Reference in New Issue
Block a user