]> Cypherpunks repositories - gostls13.git/commitdiff
go spec: attempt at clarifying language for "append"
authorRobert Griesemer <gri@golang.org>
Tue, 19 Apr 2011 21:38:49 +0000 (14:38 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 19 Apr 2011 21:38:49 +0000 (14:38 -0700)
Specifically, fix a wrong comment.

Fixes #1717.

R=r, rsc
CC=golang-dev
https://golang.org/cl/4445050

doc/go_spec.html

index f8fe5974a14bff2512bfb38faccd6c5672c6a5ac..38a9877bf275bd3387bb33e7fbf083770fcff495 100644 (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>