From 58d296065501958bbc7aeb8abea016b221b53f02 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-It is a shorthand for a regular variable declaration
+It is shorthand for a regular variable declaration
with initializer expressions but no types:
-and is a shortcut for a slice operation applied to an array:
+and is shorthand for a slice operation applied to an array:
@@ -2462,7 +2462,7 @@ is also a pointer to a struct,
x.y.z is shorthand
for (*(*x).y).z, and so on.
If x contains an anonymous field of type *A,
where A is also a struct type,
-x.f is a shortcut for (*x.A).f.
+x.f is shorthand for (*x.A).f.
@@ -2519,10 +2519,9 @@ a[x]
-denotes the element of the array, slice, string or map a indexed by x.
-The value x is called the
-index or map key, respectively. The following
-rules apply:
+denotes the element of the array, pointer to array, slice, string or map a indexed by x.
+The value x is called the index or map key, respectively.
+The following rules apply:
@@ -2537,44 +2536,48 @@ If a is not a map:
-For a of type A or *A
-where A is an array type:
+For a of array type A:
a is nil or if x is out of range at run time,
+ x is out of range at run time,
a run-time panic occursa[x] is the array element at index x and the type of
a[x] is the element type of A
-For a of type S where S is a slice type:
+For a of pointer to array type:
+
a[x] is shorthand for (*a)[x]
+For a of slice type S:
nil or if x is out of range at run time,
+ x is out of range at run time,
a run-time panic occursa[x] is the slice element at index x and the type of
a[x] is the element type of S
-For a of type T
-where T is a string type:
+For a of string type:
a is also constantx is out of range at run time,
a run-time panic occursa[x] is the byte at index x and the type of
+ a[x] is the non-constant byte value at index x and the type of
a[x] is bytea[x] may not be assigned to
-For a of type M
-where M is a map type:
+For a of map type M:
x's type must be
@@ -2628,9 +2631,9 @@ a[low : high]
-constructs a substring or slice. The indices low and
-high select which elements appear in the result. The result has
-indices starting at 0 and length equal to
+constructs a substring or slice. The indices low and
+high select which elements of operand a appear
+in the result. The result has indices starting at 0 and length equal to
high - low.
After slicing the array a
-For arrays or strings, the indices low and high are
-in range if 0 <= low <= high <= len(a),
+If a is a pointer to an array, a[low : high] is shorthand for
+(*a)[low : high].
+
+For arrays or strings, the indices are in range if
+0 <= low <= high <= len(a),
otherwise they are out of range.
For slices, the upper index bound is the slice capacity cap(a) rather than the length.
A constant index must be non-negative and representable by a value of type
int.
-If both indices
-are constant, they must satisfy low <= high. If a is nil
-or if the indices are out of range at run time, a run-time panic occurs.
+If both indices are constant, they must satisfy low <= high.
+If the indices are out of range at run time, a run-time panic occurs.
-If the sliced operand is a string or slice, the result of the slice operation
-is a string or slice of the same type.
+Except for untyped strings, if the sliced operand is a string or slice,
+the result of the slice operation is a non-constant value of the same type as the operand.
+For untyped string operands the result is a non-constant value of type string.
If the sliced operand is an array, it must be addressable
and the result of the slice operation is a slice with the same element type as the array.
+If the sliced operand of a valid slice expression is a nil slice, the result
+is a nil slice.
+