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

Side by Side Diff: doc/go_spec.html

Issue 2627043: code review 2627043: go spec: append built-in (Closed)
Patch Set: code review 2627043: go spec: append built-in Created 14 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 Architecture-specific convenience types: 1485 Architecture-specific convenience types:
1486 complex float int uint uintptr 1486 complex float int uint uintptr
1487 1487
1488 Constants: 1488 Constants:
1489 true false iota 1489 true false iota
1490 1490
1491 Zero value: 1491 Zero value:
1492 nil 1492 nil
1493 1493
1494 Functions: 1494 Functions:
1495 » cap close closed cmplx copy imag len make 1495 » append cap close closed cmplx copy imag len
1496 » new panic print println real recover 1496 » make new panic print println real recover
1497 </pre> 1497 </pre>
1498 1498
1499 1499
1500 <h3 id="Exported_identifiers">Exported identifiers</h3> 1500 <h3 id="Exported_identifiers">Exported identifiers</h3>
1501 1501
1502 <p> 1502 <p>
1503 An identifier may be <i>exported</i> to permit access to it from another package 1503 An identifier may be <i>exported</i> to permit access to it from another package
1504 using a <a href="#Qualified_identifiers">qualified identifier</a>. An identifier 1504 using a <a href="#Qualified_identifiers">qualified identifier</a>. An identifier
1505 is exported if both: 1505 is exported if both:
1506 </p> 1506 </p>
(...skipping 3013 matching lines...) Expand 10 before | Expand all | Expand 10 after
4520 </p> 4520 </p>
4521 4521
4522 <pre> 4522 <pre>
4523 s := make([]int, 10, 100) // slice with len(s) == 10, cap(s) == 100 4523 s := make([]int, 10, 100) // slice with len(s) == 10, cap(s) == 100
4524 s := make([]int, 10) // slice with len(s) == cap(s) == 10 4524 s := make([]int, 10) // slice with len(s) == cap(s) == 10
4525 c := make(chan int, 10) // channel with a buffer size of 10 4525 c := make(chan int, 10) // channel with a buffer size of 10
4526 m := make(map[string] int, 100) // map with initial space for 100 elements 4526 m := make(map[string] int, 100) // map with initial space for 100 elements
4527 </pre> 4527 </pre>
4528 4528
4529 4529
4530 <h3 id="Copying_slices">Copying slices</h3> 4530 <h3 id="Appending_and_copying_slices">Appending to and copying slices</h3>
4531 4531
4532 <p> 4532 <p>
4533 The built-in function <code>copy</code> copies slice elements from 4533 Two built-in functions assist in common slice operations.
4534 </p>
4535
4536 <p>
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. Each value must be
4539 <a href="#Assignability">assignable</a> to the slice's element type.
4540 </p>
4541
4542 <pre class="grammar">
4543 append(s []T, x ...T) []T
4544 </pre>
4545
4546 <p>
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
4549 both the existing slice elements and the additional values. Thus, the returned
4550 slice may refer to a different underlying array.·
4551 </p>
4552
4553 <pre>
4554 s0 := []int{0, 0}
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}
4557 s3 := append(s2, s0...) // append a slice s3 == []int{0, 0, 2, 3 , 5, 7, 0, 0}
4558 </pre>
4559
4560 <p>
4561 The function <code>copy</code> copies slice elements from
4534 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
4535 number of elements copied. Source and destination may overlap. 4563 number of elements copied. Source and destination may overlap.
4536 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
4537 <a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>. 4565 <a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>.
4538 The number of arguments copied is the minimum of 4566 The number of arguments copied is the minimum of
4539 <code>len(src)</code> and <code>len(dst)</code>. 4567 <code>len(src)</code> and <code>len(dst)</code>.
4540 As a special case, <code>copy</code> also accepts a destination argument assigna ble 4568 As a special case, <code>copy</code> also accepts a destination argument assigna ble
4541 to type <code>[]byte</code> with a source argument of a string type. 4569 to type <code>[]byte</code> with a source argument of a string type.
4542 This form copies the bytes from the string into the byte slice. 4570 This form copies the bytes from the string into the byte slice.
4543 </p> 4571 </p>
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
5196 <code>unsafe.Alignof(x[0])</code>, but at least 1. 5224 <code>unsafe.Alignof(x[0])</code>, but at least 1.
5197 </li> 5225 </li>
5198 </ol> 5226 </ol>
5199 5227
5200 <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>
5201 <ul> 5229 <ul>
5202 <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>
5203 <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>
5204 <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>
5205 </ul> 5233 </ul>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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