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

Side by Side Diff: doc/go_spec.html

Issue 7307083: code review 7307083: spec: clarify when range x does not evaluate x (Closed)
Patch Set: diff -r 18067ce7e9ba https://code.google.com/p/go/ Created 12 years, 1 month 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 <!--{ 1 <!--{
2 "Title": "The Go Programming Language Specification", 2 "Title": "The Go Programming Language Specification",
3 "Subtitle": "Version of February 11, 2013", 3 "Subtitle": "Version of February 11, 2013",
4 "Path": "/ref/spec" 4 "Path": "/ref/spec"
5 }--> 5 }-->
6 6
7 <!-- 7 <!--
8 TODO 8 TODO
9 [ ] need language about function/method calls and parameter passing rules 9 [ ] need language about function/method calls and parameter passing rules
10 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere 10 [ ] last paragraph of #Assignments (constant promotion) should be elsewhere
(...skipping 4359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 <a href="#Receive_operator">receive operations</a>. 4370 <a href="#Receive_operator">receive operations</a>.
4371 As with an assignment, the operands on the left must be 4371 As with an assignment, the operands on the left must be
4372 <a href="#Address_operators">addressable</a> or map index expressions; they 4372 <a href="#Address_operators">addressable</a> or map index expressions; they
4373 denote the iteration variables. If the range expression is a channel, only 4373 denote the iteration variables. If the range expression is a channel, only
4374 one iteration variable is permitted, otherwise there may be one or two. In the l atter case, 4374 one iteration variable is permitted, otherwise there may be one or two. In the l atter case,
4375 if the second iteration variable is the <a href="#Blank_identifier">blank identi fier</a>, 4375 if the second iteration variable is the <a href="#Blank_identifier">blank identi fier</a>,
4376 the range clause is equivalent to the same clause with only the first variable p resent. 4376 the range clause is equivalent to the same clause with only the first variable p resent.
4377 </p> 4377 </p>
4378 4378
4379 <p> 4379 <p>
4380 The range expression is evaluated once before beginning the loop 4380 The range expression is evaluated once before beginning the loop,
4381 except if the expression is an array, in which case, depending on 4381 with one exception. If the range expression is an array or a pointer to an array
4382 the expression, it might not be evaluated (see below). 4382 and only the first iteration value is present, only the range expression's
4383 length is evaluated; if that length may be constant
r 2013/02/11 14:29:54 if that length is constant by definition (see ...)
rsc 2013/02/15 18:18:23 Done.
4384 (see §<a href="#Length_and_capacity">Length and capacity</a>),
4385 the range expression itself will not be evaluated.
4386 </p>
4387
4388 <p>
4383 Function calls on the left are evaluated once per iteration. 4389 Function calls on the left are evaluated once per iteration.
4384 For each iteration, iteration values are produced as follows: 4390 For each iteration, iteration values are produced as follows:
4385 </p> 4391 </p>
4386 4392
4387 <pre class="grammar"> 4393 <pre class="grammar">
4388 Range expression 1st value 2nd value (if 2nd v ariable is present) 4394 Range expression 1st value 2nd value (if 2nd v ariable is present)
4389 4395
4390 array or slice a [n]E, *[n]E, or []E index i int a[i] E 4396 array or slice a [n]E, *[n]E, or []E index i int a[i] E
4391 string s string type index i int see below rune 4397 string s string type index i int see below rune
4392 map m map[K]V key k K m[k] V 4398 map m map[K]V key k K m[k] V
4393 channel c chan E, &lt;-chan E element e E 4399 channel c chan E, &lt;-chan E element e E
4394 </pre> 4400 </pre>
4395 4401
4396 <ol> 4402 <ol>
4397 <li> 4403 <li>
4398 For an array, pointer to array, or slice value <code>a</code>, the index iterati on 4404 For an array, pointer to array, or slice value <code>a</code>, the index iterati on
4399 values are produced in increasing order, starting at element index 0. As a speci al 4405 values are produced in increasing order, starting at element index 0.
4400 case, if only the first iteration variable is present, the range loop produces 4406 If only the first iteration variable is present, the range loop produces
4401 iteration values from 0 up to <code>len(a)</code> and does not index into the ar ray 4407 iteration values from 0 up to <code>len(a)</code> and does not index into the ar ray
4402 or slice itself. For a <code>nil</code> slice, the number of iterations is 0. 4408 or slice itself. For a <code>nil</code> slice, the number of iterations is 0.
4403 </li> 4409 </li>
4404 4410
4405 <li> 4411 <li>
4406 For a string value, the "range" clause iterates over the Unicode code points 4412 For a string value, the "range" clause iterates over the Unicode code points
4407 in the string starting at byte index 0. On successive iterations, the index val ue will be the 4413 in the string starting at byte index 0. On successive iterations, the index val ue will be the
4408 index of the first byte of successive UTF-8-encoded code points in the string, 4414 index of the first byte of successive UTF-8-encoded code points in the string,
4409 and the second value, of type <code>rune</code>, will be the value of 4415 and the second value, of type <code>rune</code>, will be the value of
4410 the corresponding code point. If the iteration encounters an invalid 4416 the corresponding code point. If the iteration encounters an invalid
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
5693 </li> 5699 </li>
5694 5700
5695 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code> is the same as 5701 <li>For a variable <code>x</code> of array type: <code>unsafe.Alignof(x)</code> is the same as
5696 <code>unsafe.Alignof(x[0])</code>, but at least 1. 5702 <code>unsafe.Alignof(x[0])</code>, but at least 1.
5697 </li> 5703 </li>
5698 </ol> 5704 </ol>
5699 5705
5700 <p> 5706 <p>
5701 A struct or array type has size zero if it contains no fields (or elements, resp ectively) that have a size greater than zero. Two distinct zero-size variables m ay have the same address in memory. 5707 A struct or array type has size zero if it contains no fields (or elements, resp ectively) that have a size greater than zero. Two distinct zero-size variables m ay have the same address in memory.
5702 </p> 5708 </p>
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