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

Delta Between Two Patch Sets: doc/go_spec.html

Issue 156089: code review 156089: Allow optional second expression in slice expressions. (Closed)
Left Patch Set: code review 156089: Allow optional second expression in slice expressions. Created 14 years, 4 months ago
Right Patch Set: code review 156089: Allow optional second expression in slice expressions. Created 14 years, 4 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 <!-- The Go Programming Language Specification --> 1 <!-- The Go Programming Language Specification -->
2 2
3 <!-- 3 <!--
4 Todo 4 Todo
5 [ ] clarify: two equal lowercase identifiers from different packages denote diff erent objects 5 [ ] clarify: two equal lowercase identifiers from different packages denote diff erent objects
6 [ ] need language about function/method calls and parameter passing rules 6 [ ] need language about function/method calls and parameter passing rules
7 [ ] need to say something about "scope" of selectors? 7 [ ] need to say something about "scope" of selectors?
8 [ ] clarify what a field name is in struct declarations 8 [ ] clarify what a field name is in struct declarations
9 (struct{T} vs struct {T T} vs struct {t T}) 9 (struct{T} vs struct {T T} vs struct {t T})
10 [ ] need explicit language about the result type of operations 10 [ ] need explicit language about the result type of operations
(...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 For a string, array, or slice <code>a</code>, the primary expression 2333 For a string, array, or slice <code>a</code>, the primary expression
2334 </p> 2334 </p>
2335 2335
2336 <pre> 2336 <pre>
2337 a[lo : hi] 2337 a[lo : hi]
2338 </pre> 2338 </pre>
2339 2339
2340 <p> 2340 <p>
2341 constructs a substring or slice. The index expressions <code>lo</code> and 2341 constructs a substring or slice. The index expressions <code>lo</code> and
2342 <code>hi</code> select which elements appear in the result. The result has 2342 <code>hi</code> select which elements appear in the result. The result has
2343 indexes starting at 0 and length equal to the difference 2343 indexes starting at 0 and length equal to
2344 <code>hi</code>&nbsp;-<code>&nbsp;lo</code>. 2344 <code>hi</code>&nbsp;-&nbsp;<code>lo</code>.
2345 After slicing the array <code>a</code> 2345 After slicing the array <code>a</code>
2346 </p> 2346 </p>
2347 2347
2348 <pre> 2348 <pre>
2349 a := [4]int{1, 2, 3, 4, 5}; 2349 a := [5]int{1, 2, 3, 4, 5};
2350 s := a[1:4]; 2350 s := a[1:4];
2351 </pre> 2351 </pre>
2352 2352
2353 <p> 2353 <p>
2354 the slice <code>s</code> has type <code>[]int</code>, length 3, capacity 4, and elements 2354 the slice <code>s</code> has type <code>[]int</code>, length 3, capacity 4, and elements
2355 </p> 2355 </p>
2356 2356
2357 <pre> 2357 <pre>
2358 s[0] == 2 // == a[lo + 0] 2358 s[0] == 2
2359 s[1] == 3 // == a[lo + 1] 2359 s[1] == 3
2360 s[2] == 4 // == a[lo + 2] == a[hi - 1] 2360 s[2] == 4
2361 </pre> 2361 </pre>
2362 2362
2363 <p> 2363 <p>
2364 For convenience, the <code>hi</code> expression may be omitted; the notation 2364 For convenience, the <code>hi</code> expression may be omitted; the notation
2365 <code>a[lo :]</code> stands for <code>a[lo : len(a)]</code>. 2365 <code>a[lo :]</code> is shorthand for <code>a[lo : len(a)]</code>.
2366 For arrays or strings, the indexes 2366 For arrays or strings, the indexes
2367 <code>lo</code> and <code>hi</code> must satisfy 2367 <code>lo</code> and <code>hi</code> must satisfy
2368 0 &lt;= <code>lo</code> &lt;= <code>hi</code> &lt;= length; 2368 0 &lt;= <code>lo</code> &lt;= <code>hi</code> &lt;= length;
2369 for slices, the upper bound is the capacity rather than the length. 2369 for slices, the upper bound is the capacity rather than the length.
2370 </p> 2370 </p>
2371 2371
2372 <p> 2372 <p>
2373 If the sliced operand is a string or slice, the result of the slice operation 2373 If the sliced operand is a string or slice, the result of the slice operation
2374 is a string or slice of the same type. 2374 is a string or slice of the same type.
2375 If the sliced operand is an array, the result of the slice operation is a slice 2375 If the sliced operand is an array, the result of the slice operation is a slice
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after
4216 The built-in function <code>copy</code> copies array or slice elements from 4216 The built-in function <code>copy</code> copies array or slice elements from
4217 a source <code>src</code> to a destination <code>dst</code> and returns the 4217 a source <code>src</code> to a destination <code>dst</code> and returns the
4218 number of elements copied. Source and destination may overlap. 4218 number of elements copied. Source and destination may overlap.
4219 Both arguments must have the same element type <code>T</code> and must be 4219 Both arguments must have the same element type <code>T</code> and must be
4220 <a href="#Assignment_compatibility">assignment compatible</a> to a slice 4220 <a href="#Assignment_compatibility">assignment compatible</a> to a slice
4221 of type <code>[]T</code>. The number of arguments copied is the minimum of 4221 of type <code>[]T</code>. The number of arguments copied is the minimum of
4222 <code>len(src)</code> and <code>len(dst)</code>. 4222 <code>len(src)</code> and <code>len(dst)</code>.
4223 </p> 4223 </p>
4224 4224
4225 <pre class="grammar"> 4225 <pre class="grammar">
4226 copy(dst []T, src []T) int 4226 copy(dst, src []T) int
4227 </pre> 4227 </pre>
4228 4228
4229 <p> 4229 <p>
4230 Examples: 4230 Examples:
4231 </p> 4231 </p>
4232 4232
4233 <pre> 4233 <pre>
4234 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}; 4234 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7};
4235 var s = make([]int, 6); 4235 var s = make([]int, 6);
4236 n1 := copy(s, &amp;a); // n1 == 6, s == []int{0, 1, 2, 3, 4, 5} 4236 n1 := copy(s, &amp;a); // n1 == 6, s == []int{0, 1, 2, 3, 4, 5}
4237 n2 := copy(s, s[3:]); // n2 == 3, s == []int{3, 4, 5, 3, 4, 5} 4237 n2 := copy(s, s[2:]); // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
4238 </pre> 4238 </pre>
4239 4239
4240 4240
4241 <h3 id="Bootstrapping">Bootstrapping</h3> 4241 <h3 id="Bootstrapping">Bootstrapping</h3>
4242 4242
4243 <p> 4243 <p>
4244 Current implementations provide several built-in functions useful during 4244 Current implementations provide several built-in functions useful during
4245 bootstrapping. These functions are documented for completeness but are not 4245 bootstrapping. These functions are documented for completeness but are not
4246 guaranteed to stay in the language. They do not return a result. 4246 guaranteed to stay in the language. They do not return a result.
4247 </p> 4247 </p>
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
4663 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code> is the same as 4663 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code> is the same as
4664 <code>unsafe.Alignof(x[0])</code>, but at least 1. 4664 <code>unsafe.Alignof(x[0])</code>, but at least 1.
4665 </ol> 4665 </ol>
4666 4666
4667 <h2 id="Implementation_differences"><span class="alert">Implementation differenc es - TODO</span></h2> 4667 <h2 id="Implementation_differences"><span class="alert">Implementation differenc es - TODO</span></h2>
4668 <ul> 4668 <ul>
4669 <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li> 4669 <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li>
4670 <li><span class="alert">Method expressions are not implemented.</span></ li> 4670 <li><span class="alert">Method expressions are not implemented.</span></ li>
4671 <li><span class="alert">Gccgo allows only one init() function per source file.</span></li> 4671 <li><span class="alert">Gccgo allows only one init() function per source file.</span></li>
4672 </ul> 4672 </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