Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(366)

Delta Between Two Patch Sets: doc/go_spec.html

Issue 2627043: code review 2627043: go spec: append built-in (Closed)
Left Patch Set: Created 13 years, 5 months ago
Right Patch Set: code review 2627043: go spec: append built-in Created 13 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 <!-- title The Go Programming Language Specification --> 1 <!-- title The Go Programming Language Specification -->
2 <!-- subtitle Version of Oct 22, 2010 --> 2 <!-- subtitle Version of Oct 25, 2010 -->
3 3
4 <!-- 4 <!--
5 TODO 5 TODO
6 [ ] need language about function/method calls and parameter passing rules 6 [ ] need language about function/method calls and parameter passing rules
7 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere 7 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere
8 and mention assignment to empty interface. 8 and mention assignment to empty interface.
9 [ ] need to say something about "scope" of selectors? 9 [ ] need to say something about "scope" of selectors?
10 [ ] clarify what a field name is in struct declarations 10 [ ] clarify what a field name is in struct declarations
11 (struct{T} vs struct {T T} vs struct {t T}) 11 (struct{T} vs struct {T T} vs struct {t T})
12 [ ] need explicit language about the result type of operations 12 [ ] need explicit language about the result type of operations
(...skipping 4515 matching lines...) Expand 10 before | Expand all | Expand 10 after
4528 4528
4529 4529
4530 <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3> 4530 <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
4531 4531
4532 <p> 4532 <p>
4533 Two built-in functions assist in common slice operations. 4533 Two built-in functions assist in common slice operations.
4534 </p> 4534 </p>
4535 4535
4536 <p> 4536 <p>
4537 The function <code>append</code> appends zero or more values <code>x</code> 4537 The function <code>append</code> appends zero or more values <code>x</code>
4538 to a slice <code>s</code> and returns the resulting slice. The values must 4538 to a slice <code>s</code> and returns the resulting slice. Each value must be
4539 be <a href="#Assignability">assignable</a> to the slice's element type or the 4539 <a href="#Assignability">assignable</a> to the slice's element type.
4540 value must be of the form <code>v...</code> and the type of <code>v</code> must
r 2010/10/22 22:07:18 i find this very hard to follow. how about just d
4541 be identical to the type of <code>s</code>.
4542 </p> 4540 </p>
4543 4541
4544 <pre class="grammar"> 4542 <pre class="grammar">
4545 append(s []T, x ...T) []T 4543 append(s []T, x ...T) []T
4546 </pre> 4544 </pre>
4547 4545
4548 <p> 4546 <p>
4549 If the capacity of <code>s</code> is not large enough to fit the additional 4547 If the capacity of <code>s</code> is not large enough to fit the additional
4550 values, <code>append</code> allocates a new, sufficiently large slice that fits 4548 values, <code>append</code> allocates a new, sufficiently large slice that fits
4551 both the existing slice elements and the additional values. Thus, the resulting 4549 both the existing slice elements and the additional values. Thus, the returned
4552 slice may have a different underlying array.· 4550 slice may refer to a different underlying array.·
4553 </p> 4551 </p>
4554 4552
4555 <pre> 4553 <pre>
4556 s0 := []int{0, 0} 4554 s0 := []int{0, 0}
4557 s1 := append(s0, 2) // append a single element s1 == []int{0, 0, 2} 4555 s1 := append(s0, 2) // append a single element s1 == []int{0, 0, 2}
4558 s2 := append(s1, 3, 5, 7) // append multiple elements s2 == []int{0, 0, 2, 3 , 5, 7} 4556 s2 := append(s1, 3, 5, 7) // append multiple elements s2 == []int{0, 0, 2, 3 , 5, 7}
4559 s3 := append(s2, s0...) // append a slice s3 == []int{0, 0, 2, 3 , 5, 7, 0, 0} 4557 s3 := append(s2, s0...) // append a slice s3 == []int{0, 0, 2, 3 , 5, 7, 0, 0}
4560 s4 := append(nil, s1...) // make a copy of a slice s4 == []int{0, 0, 2}
4561 </pre> 4558 </pre>
4562 4559
4563 <p> 4560 <p>
4564 The function <code>copy</code> copies slice elements from 4561 The function <code>copy</code> copies slice elements from
4565 a source <code>src</code> to a destination <code>dst</code> and returns the 4562 a source <code>src</code> to a destination <code>dst</code> and returns the
4566 number of elements copied. Source and destination may overlap. 4563 number of elements copied. Source and destination may overlap.
4567 Both arguments must have <a href="#Type_identity">identical</a> element type <co de>T</code> and must be 4564 Both arguments must have <a href="#Type_identity">identical</a> element type <co de>T</code> and must be
4568 <a href="#Assignability">assignable</a> to a slice 4565 <a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>.
4569 of type <code>[]T</code>. The number of arguments copied is the minimum of 4566 The number of arguments copied is the minimum of
4570 <code>len(src)</code> and <code>len(dst)</code>. 4567 <code>len(src)</code> and <code>len(dst)</code>.
4568 As a special case, <code>copy</code> also accepts a destination argument assigna ble
4569 to type <code>[]byte</code> with a source argument of a string type.
4570 This form copies the bytes from the string into the byte slice.
4571 </p> 4571 </p>
4572 4572
4573 <pre class="grammar"> 4573 <pre class="grammar">
4574 copy(dst, src []T) int 4574 copy(dst, src []T) int
4575 copy(dst []byte, src string) int
4575 </pre> 4576 </pre>
4576 4577
4577 <p> 4578 <p>
4578 Examples: 4579 Examples:
4579 </p> 4580 </p>
4580 4581
4581 <pre> 4582 <pre>
4582 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7} 4583 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
4583 var s = make([]int, 6) 4584 var s = make([]int, 6)
4584 n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5} 4585 var b = make([]byte, 5)
4585 n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5} 4586 n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5}
4587 n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
4588 n3 := copy(b, "Hello, World!") // n3 == 5, b == []byte("Hello")
4586 </pre> 4589 </pre>
4587 4590
4588 <h3 id="Complex_numbers">Assembling and disassembling complex numbers</h3> 4591 <h3 id="Complex_numbers">Assembling and disassembling complex numbers</h3>
4589 4592
4590 <p> 4593 <p>
4591 Three functions assemble and disassemble complex numbers. 4594 Three functions assemble and disassemble complex numbers.
4592 The built-in function <code>cmplx</code> constructs a complex 4595 The built-in function <code>cmplx</code> constructs a complex
4593 value from a floating-point real and imaginary part, while 4596 value from a floating-point real and imaginary part, while
4594 <code>real</code> and <code>imag</code> 4597 <code>real</code> and <code>imag</code>
4595 extract the real and imaginary parts of a complex value. 4598 extract the real and imaginary parts of a complex value.
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
5221 <code>unsafe.Alignof(x[0])</code>, but at least 1. 5224 <code>unsafe.Alignof(x[0])</code>, but at least 1.
5222 </li> 5225 </li>
5223 </ol> 5226 </ol>
5224 5227
5225 <h2 id="Implementation_differences"><span class="alert">Implementation differenc es - TODO</span></h2> 5228 <h2 id="Implementation_differences"><span class="alert">Implementation differenc es - TODO</span></h2>
5226 <ul> 5229 <ul>
5227 <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li> 5230 <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li>
5228 <li><span class="alert">Gccgo: Method expressions are partially implemen ted.</span></li> 5231 <li><span class="alert">Gccgo: Method expressions are partially implemen ted.</span></li>
5229 <li><span class="alert">Gccgo: allows only one init() function per sourc e file.</span></li> 5232 <li><span class="alert">Gccgo: allows only one init() function per sourc e file.</span></li>
5230 </ul> 5233 </ul>
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b