1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:50:22 -07:00

go spec: attempt at clarifying language for "append"

Specifically, fix a wrong comment.

Fixes #1717.

R=r, rsc
CC=golang-dev
https://golang.org/cl/4445050
This commit is contained in:
Robert Griesemer 2011-04-19 14:38:49 -07:00
parent 3cb973ff65
commit 0f7acf1114

View File

@ -1,5 +1,5 @@
<!-- title The Go Programming Language Specification -->
<!-- subtitle Version of Apr 5, 2011 -->
<!-- subtitle Version of Apr 19, 2011 -->
<!--
TODO
@ -4541,13 +4541,14 @@ Two built-in functions assist in common slice operations.
<p>
The function <code>append</code> appends zero or more values <code>x</code>
to a slice <code>s</code> and returns the resulting slice, with the same type
as s. Each value must be <a href="#Assignability">assignable</a> to the slice's
element type.
to <code>s</code> of type <code>S</code>, which must be a slice type, and
returns the resulting slice, also of type <code>S</code>.
Each value <code>x</code> must be <a href="#Assignability">assignable</a> to
the <a href="#Slice_types">element type</a> of <code>S</code>.
</p>
<pre class="grammar">
append(s S, x ...T) S // S is assignable to []T
append(s S, x ...T) S // T is the element type of S
</pre>
<p>
@ -4562,6 +4563,9 @@ 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}
var t []interface{}
t = append(t, 42, 3.1415, "foo") t == []interface{}{42, 3.1415, "foo"}
</pre>
<p>