Hello email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org (cc:
I'd like you to review this change to
spec: clarify re-use of underlying arrays in slice operations
Documents the status quo; not a language change. That said,
please note the slight rewording for append, where the old
language (almost) implied that the underlying array is shared
if large enough. The slight rewording makes it clear that we
do not require that property.
Fixes issue 5818.
Please review this at https://codereview.appspot.com/14419054/
Affected files (+17, -24 lines):
@@ -1,6 +1,6 @@
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of Oct 7, 2013",
+ "Subtitle": "Version of Oct 9, 2013",
@@ -839,7 +839,7 @@
<h3 id="Slice_types">Slice types</h3>
-A slice is a descriptor for a contiguous segment of an array and
+A slice is a descriptor for a contiguous segment of an <i>underlying
provides access to a numbered sequence of elements from that array.
A slice type denotes the set of all slices of arrays of its element type.
The value of an uninitialized slice is <code>nil</code>.
@@ -879,26 +879,18 @@
made using the built-in function
which takes a slice type
-and parameters specifying the length and optionally the capacity:
+and parameters specifying the length and optionally the capacity.
+A slice created with <code>make</code> always allocates a new, hidden array
+to which the returned slice value refers. That is, executing
make(T, length, capacity)
-A call to <code>make</code> allocates a new, hidden array to which the
-slice value refers. That is, executing
-make(T, length, capacity)
-produces the same slice as allocating an array and slicing it, so these
-result in the same slice:
+produces the same slice as allocating an array and <a
+it, so these two examples result in the same slice:
@@ -910,8 +902,8 @@
Like arrays, slices are always one-dimensional but may be composed to
With arrays of arrays, the inner arrays are, by construction, always the
-however with slices of slices (or arrays of slices), the lengths may vary
-Moreover, the inner slices must be allocated individually (with
+however with slices of slices (or arrays of slices), the inner lengths may
+Moreover, the inner slices must be initialized individually.
<h3 id="Struct_types">Struct types</h3>
@@ -2707,7 +2699,8 @@
If the sliced operand of a valid slice expression is a <code>nil</code>
slice, the result
-is a <code>nil</code> slice.
+is a <code>nil</code> slice. Otherwise, the result shares its underlying
array with the
<h4>Full slice expressions</h4>
@@ -5360,10 +5353,10 @@
-If the capacity of <code>s</code> is not large enough to fit the additional
+The resulting slice may refer to a different underlying array then
+For instance, if the capacity of <code>s</code> is not large enough to fit
values, <code>append</code> allocates a new, sufficiently large slice that
-both the existing slice elements and the additional values. Thus, the
-slice may refer to a different underlying array.
+both the existing slice elements and the additional values.
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
For more options, visit https://groups.google.com/groups/opt_out.