From 9f75dd7f25d0171bb0b32522de41b252d6eef111 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-It is shorthand for a regular variable declaration
+It is a shorthand for a regular variable declaration
with initializer expressions but no types:
-and is shorthand for a slice operation applied to an array:
+and is a shortcut 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 shorthand for (*x.A).f
.
+x.f
is a shortcut for (*x.A).f
.
@@ -2519,9 +2519,10 @@ a[x]
-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:
+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:
@@ -2536,48 +2537,44 @@ If a
is not a map:
-For a
of array type A
:
+For a
of type A
or *A
+where A
is an array type:
x
is out of range at run time,
+ a
is nil
or if 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 pointer to array type:
-
a[x]
is shorthand for (*a)[x]
-For a
of slice type S
:
+For a
of type S
where S
is a slice type:
x
is out of range at run time,
+ nil
or if 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 string type:
+For a
of type T
+where T
is a string type:
a
is also constantx
is out of range at run time,
a run-time panic occursa[x]
is the non-constant byte value at index x
and the type of
+ a[x]
is the byte at index x
and the type of
a[x]
is byte
a[x]
may not be assigned to
-For a
of map type M
:
+For a
of type M
+where M
is a map type:
x
's type must be
@@ -2631,9 +2628,9 @@ a[low : high]
-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
+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
high
- low
.
After slicing the array 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)
,
+For arrays or strings, the indices low
and high
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 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 a
is nil
+or if the indices are out of range at run time, a run-time panic occurs.
-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 a string or slice, the result of the slice operation
+is a string or slice of the same type.
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.
-