Skip to content

Commit 85177f4

Browse files
committed
spec: remove vestiges referring to iotas being incremented
https://golang.org/cl/71750 specifies iota values as indices, thus making them independent from nested constant declarations. This CL removes some of the comments in the examples that were still referring to the old notion of iotas being incremented and reset. As an aside, please note that the spec still permits the use of iota in a nested function (like before). Specifically, the following cases are permitted by the spec (as before): 1) const _ = len([iota]int{}) 2) const _ = unsafe.Sizeof(func(){ _ = iota }) For #15550. Change-Id: I9e5fec75daf7b628b1e08d970512397e9c348923 Reviewed-on: https://go-review.googlesource.com/71912 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 12c9d75 commit 85177f4

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

doc/go_spec.html

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of October 18, 2017",
3+
"Subtitle": "Version of October 19, 2017",
44
"Path": "/ref/spec"
55
}-->
66

@@ -1837,7 +1837,7 @@ <h3 id="Constant_declarations">Constant declarations</h3>
18371837

18381838
<p>
18391839
Within a parenthesized <code>const</code> declaration list the
1840-
expression list may be omitted from any but the first declaration.
1840+
expression list may be omitted from any but the first ConstSpec.
18411841
Such an empty list is equivalent to the textual substitution of the
18421842
first preceding non-empty expression list and its type if any.
18431843
Omitting the list of expressions is therefore equivalent to
@@ -1872,46 +1872,45 @@ <h3 id="Iota">Iota</h3>
18721872
</p>
18731873

18741874
<pre>
1875-
const ( // iota is reset to 0
1875+
const (
18761876
c0 = iota // c0 == 0
18771877
c1 = iota // c1 == 1
18781878
c2 = iota // c2 == 2
18791879
)
18801880

1881-
const ( // iota is reset to 0
1882-
a = 1 &lt;&lt; iota // a == 1
1883-
b = 1 &lt;&lt; iota // b == 2
1884-
c = 3 // c == 3 (iota is not used but still incremented)
1885-
d = 1 &lt;&lt; iota // d == 8
1881+
const (
1882+
a = 1 &lt;&lt; iota // a == 1 (iota == 0)
1883+
b = 1 &lt;&lt; iota // b == 2 (iota == 1)
1884+
c = 3 // c == 3 (iota == 2, unused)
1885+
d = 1 &lt;&lt; iota // d == 8 (iota == 3)
18861886
)
18871887

1888-
const ( // iota is reset to 0
1888+
const (
18891889
u = iota * 42 // u == 0 (untyped integer constant)
18901890
v float64 = iota * 42 // v == 42.0 (float64 constant)
18911891
w = iota * 42 // w == 84 (untyped integer constant)
18921892
)
18931893

1894-
const x = iota // x == 0 (iota has been reset)
1895-
const y = iota // y == 0 (iota has been reset)
1894+
const x = iota // x == 0
1895+
const y = iota // y == 0
18961896
</pre>
18971897

18981898
<p>
1899-
Within an ExpressionList, the value of each <code>iota</code> is the same because
1900-
it is only incremented after each ConstSpec:
1899+
By definition, multiple uses of <code>iota</code> in the same ConstSpec all have the same value:
19011900
</p>
19021901

19031902
<pre>
19041903
const (
1905-
bit0, mask0 = 1 &lt;&lt; iota, 1&lt;&lt;iota - 1 // bit0 == 1, mask0 == 0
1906-
bit1, mask1 // bit1 == 2, mask1 == 1
1907-
_, _ // skips iota == 2
1908-
bit3, mask3 // bit3 == 8, mask3 == 7
1904+
bit0, mask0 = 1 &lt;&lt; iota, 1&lt;&lt;iota - 1 // bit0 == 1, mask0 == 0 (iota == 0)
1905+
bit1, mask1 // bit1 == 2, mask1 == 1 (iota == 1)
1906+
_, _ // (iota == 2, unused)
1907+
bit3, mask3 // bit3 == 8, mask3 == 7 (iota == 3)
19091908
)
19101909
</pre>
19111910

19121911
<p>
1913-
This last example exploits the implicit repetition of the
1914-
last non-empty expression list.
1912+
This last example exploits the <a href="#Constant_declarations">implicit repetition</a>
1913+
of the last non-empty expression list.
19151914
</p>
19161915

19171916

0 commit comments

Comments
 (0)