FAQ
Reviewers: rsc, r, iant, ken2,

Message:
Hello rsc, r, iant, ken2 (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go


Description:
go spec: underlying arrays of arguments for append may overlap

Please review this at http://codereview.appspot.com/6567062/

Affected files:
M doc/go_spec.html


Index: doc/go_spec.html
===================================================================
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of September 26, 2012",
+ "Subtitle": "Version of September 27, 2012",
"Path": "/ref/spec"
}-->

@@ -4915,6 +4915,8 @@
where <code>T</code> is the <a href="#Slice_types">element type</a> of
<code>S</code> and the respective
<a href="#Passing_arguments_to_..._parameters">parameter passing rules</a>
apply.
+The underlying arrays of <code>s</code> and a slice argument
<code>x...</code>
+may overlap.
As a special case, <code>append</code> also accepts a first argument
assignable to type <code>[]byte</code> with a second argument of
string type followed by <code>...</code>. This form appends the
@@ -4934,15 +4936,16 @@

<pre>
s0 := []int{0, 0}
-s1 := append(s0, 2) // append a single element s1 == []int{0,
0, 2}
-s2 := append(s1, 3, 5, 7) // append multiple elements s2 == []int{0,
0, 2, 3, 5, 7}
-s3 := append(s2, s0...) // append a slice s3 == []int{0,
0, 2, 3, 5, 7, 0, 0}
+s1 := append(s0, 2) // append a single element s1 ==
[]int{0, 0, 2}
+s2 := append(s1, 3, 5, 7) // append multiple elements s2 ==
[]int{0, 0, 2, 3, 5, 7}
+s3 := append(s2, s0...) // append a slice s3 ==
[]int{0, 0, 2, 3, 5, 7, 0, 0}
+s4 := append(s3[3:6], s3[2:]...) // append overlapping slice s4 ==
[]int{3, 5, 7, 2, 3, 5, 7, 0, 0}

var t []interface{}
-t = append(t, 42, 3.1415, "foo") t ==
[]interface{}{42, 3.1415, "foo"}
+t = append(t, 42, 3.1415, "foo") t ==
[]interface{}{42, 3.1415, "foo"}

var b []byte
-b = append(b, "bar"...) // append string contents b ==
[]byte{'b', 'a', 'r' }
+b = append(b, "bar"...) // append string contents b ==
[]byte{'b', 'a', 'r' }
</pre>

<p>

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 27, '12 at 6:12p
activeSep 28, '12 at 9:21p
posts16
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase