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

Delta Between Two Patch Sets: doc/go_spec.html

Issue 2627043: code review 2627043: go spec: append built-in (Closed)
Left Patch Set: code review 2627043: go spec: append built-in 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 25, 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
(...skipping 4528 matching lines...) Expand 10 before | Expand all | Expand 10 after
4539 <a href="#Assignability">assignable</a> to the slice's element type. 4539 <a href="#Assignability">assignable</a> to the slice's element type.
4540 </p> 4540 </p>
4541 4541
4542 <pre class="grammar"> 4542 <pre class="grammar">
4543 append(s []T, x ...T) []T 4543 append(s []T, x ...T) []T
4544 </pre> 4544 </pre>
4545 4545
4546 <p> 4546 <p>
4547 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
4548 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
4549 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
4550 slice may have a different underlying array.· 4550 slice may refer to a different underlying array.·
4551 </p> 4551 </p>
4552 4552
4553 <pre> 4553 <pre>
4554 s0 := []int{0, 0} 4554 s0 := []int{0, 0}
4555 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}
4556 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}
4557 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}
4558 s4 := append(nil, s1...) // make a copy of a slice s4 == []int{0, 0, 2}
rsc1 2010/10/25 23:39:54 your mail said you removed this example
4559 </pre> 4558 </pre>
4560 4559
4561 <p> 4560 <p>
4562 The function <code>copy</code> copies slice elements from 4561 The function <code>copy</code> copies slice elements from
4563 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
4564 number of elements copied. Source and destination may overlap. 4563 number of elements copied. Source and destination may overlap.
4565 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
4566 <a href="#Assignability">assignable</a> to a slice 4565 <a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>.
4567 of type <code>[]T</code>. The number of arguments copied is the minimum of 4566 The number of arguments copied is the minimum of
4568 <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.
4569 </p> 4571 </p>
4570 4572
4571 <pre class="grammar"> 4573 <pre class="grammar">
4572 copy(dst, src []T) int 4574 copy(dst, src []T) int
4575 copy(dst []byte, src string) int
4573 </pre> 4576 </pre>
4574 4577
4575 <p> 4578 <p>
4576 Examples: 4579 Examples:
4577 </p> 4580 </p>
4578 4581
4579 <pre> 4582 <pre>
4580 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7} 4583 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
4581 var s = make([]int, 6) 4584 var s = make([]int, 6)
4582 n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5} 4585 var b = make([]byte, 5)
4583 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")
4584 </pre> 4589 </pre>
4585 4590
4586 <h3 id="Complex_numbers">Assembling and disassembling complex numbers</h3> 4591 <h3 id="Complex_numbers">Assembling and disassembling complex numbers</h3>
4587 4592
4588 <p> 4593 <p>
4589 Three functions assemble and disassemble complex numbers. 4594 Three functions assemble and disassemble complex numbers.
4590 The built-in function <code>cmplx</code> constructs a complex 4595 The built-in function <code>cmplx</code> constructs a complex
4591 value from a floating-point real and imaginary part, while 4596 value from a floating-point real and imaginary part, while
4592 <code>real</code> and <code>imag</code> 4597 <code>real</code> and <code>imag</code>
4593 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
5219 <code>unsafe.Alignof(x[0])</code>, but at least 1. 5224 <code>unsafe.Alignof(x[0])</code>, but at least 1.
5220 </li> 5225 </li>
5221 </ol> 5226 </ol>
5222 5227
5223 <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>
5224 <ul> 5229 <ul>
5225 <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>
5226 <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>
5227 <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>
5228 </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