Commit 85177f42 authored by griesemer's avatar griesemer Committed by Robert Griesemer

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/71912Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 12c9d753
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 18, 2017",
"Subtitle": "Version of October 19, 2017",
"Path": "/ref/spec"
}-->
......@@ -1837,7 +1837,7 @@ const u, v float32 = 0, 3 // u = 0.0, v = 3.0
<p>
Within a parenthesized <code>const</code> declaration list the
expression list may be omitted from any but the first declaration.
expression list may be omitted from any but the first ConstSpec.
Such an empty list is equivalent to the textual substitution of the
first preceding non-empty expression list and its type if any.
Omitting the list of expressions is therefore equivalent to
......@@ -1872,46 +1872,45 @@ It can be used to construct a set of related constants:
</p>
<pre>
const ( // iota is reset to 0
const (
c0 = iota // c0 == 0
c1 = iota // c1 == 1
c2 = iota // c2 == 2
)
const ( // iota is reset to 0
a = 1 &lt;&lt; iota // a == 1
b = 1 &lt;&lt; iota // b == 2
c = 3 // c == 3 (iota is not used but still incremented)
d = 1 &lt;&lt; iota // d == 8
const (
a = 1 &lt;&lt; iota // a == 1 (iota == 0)
b = 1 &lt;&lt; iota // b == 2 (iota == 1)
c = 3 // c == 3 (iota == 2, unused)
d = 1 &lt;&lt; iota // d == 8 (iota == 3)
)
const ( // iota is reset to 0
const (
u = iota * 42 // u == 0 (untyped integer constant)
v float64 = iota * 42 // v == 42.0 (float64 constant)
w = iota * 42 // w == 84 (untyped integer constant)
)
const x = iota // x == 0 (iota has been reset)
const y = iota // y == 0 (iota has been reset)
const x = iota // x == 0
const y = iota // y == 0
</pre>
<p>
Within an ExpressionList, the value of each <code>iota</code> is the same because
it is only incremented after each ConstSpec:
By definition, multiple uses of <code>iota</code> in the same ConstSpec all have the same value:
</p>
<pre>
const (
bit0, mask0 = 1 &lt;&lt; iota, 1&lt;&lt;iota - 1 // bit0 == 1, mask0 == 0
bit1, mask1 // bit1 == 2, mask1 == 1
_, _ // skips iota == 2
bit3, mask3 // bit3 == 8, mask3 == 7
bit0, mask0 = 1 &lt;&lt; iota, 1&lt;&lt;iota - 1 // bit0 == 1, mask0 == 0 (iota == 0)
bit1, mask1 // bit1 == 2, mask1 == 1 (iota == 1)
_, _ // (iota == 2, unused)
bit3, mask3 // bit3 == 8, mask3 == 7 (iota == 3)
)
</pre>
<p>
This last example exploits the implicit repetition of the
last non-empty expression list.
This last example exploits the <a href="#Constant_declarations">implicit repetition</a>
of the last non-empty expression list.
</p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment