|
1 | 1 | <!--{
|
2 | 2 | "Title": "The Go Programming Language Specification",
|
3 |
| - "Subtitle": "Version of October 18, 2017", |
| 3 | + "Subtitle": "Version of October 19, 2017", |
4 | 4 | "Path": "/ref/spec"
|
5 | 5 | }-->
|
6 | 6 |
|
@@ -1837,7 +1837,7 @@ <h3 id="Constant_declarations">Constant declarations</h3>
|
1837 | 1837 |
|
1838 | 1838 | <p>
|
1839 | 1839 | 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. |
1841 | 1841 | Such an empty list is equivalent to the textual substitution of the
|
1842 | 1842 | first preceding non-empty expression list and its type if any.
|
1843 | 1843 | Omitting the list of expressions is therefore equivalent to
|
@@ -1872,46 +1872,45 @@ <h3 id="Iota">Iota</h3>
|
1872 | 1872 | </p>
|
1873 | 1873 |
|
1874 | 1874 | <pre>
|
1875 |
| -const ( // iota is reset to 0 |
| 1875 | +const ( |
1876 | 1876 | c0 = iota // c0 == 0
|
1877 | 1877 | c1 = iota // c1 == 1
|
1878 | 1878 | c2 = iota // c2 == 2
|
1879 | 1879 | )
|
1880 | 1880 |
|
1881 |
| -const ( // iota is reset to 0 |
1882 |
| - a = 1 << iota // a == 1 |
1883 |
| - b = 1 << iota // b == 2 |
1884 |
| - c = 3 // c == 3 (iota is not used but still incremented) |
1885 |
| - d = 1 << iota // d == 8 |
| 1881 | +const ( |
| 1882 | + a = 1 << iota // a == 1 (iota == 0) |
| 1883 | + b = 1 << iota // b == 2 (iota == 1) |
| 1884 | + c = 3 // c == 3 (iota == 2, unused) |
| 1885 | + d = 1 << iota // d == 8 (iota == 3) |
1886 | 1886 | )
|
1887 | 1887 |
|
1888 |
| -const ( // iota is reset to 0 |
| 1888 | +const ( |
1889 | 1889 | u = iota * 42 // u == 0 (untyped integer constant)
|
1890 | 1890 | v float64 = iota * 42 // v == 42.0 (float64 constant)
|
1891 | 1891 | w = iota * 42 // w == 84 (untyped integer constant)
|
1892 | 1892 | )
|
1893 | 1893 |
|
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 |
1896 | 1896 | </pre>
|
1897 | 1897 |
|
1898 | 1898 | <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: |
1901 | 1900 | </p>
|
1902 | 1901 |
|
1903 | 1902 | <pre>
|
1904 | 1903 | const (
|
1905 |
| - bit0, mask0 = 1 << iota, 1<<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 << iota, 1<<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) |
1909 | 1908 | )
|
1910 | 1909 | </pre>
|
1911 | 1910 |
|
1912 | 1911 | <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. |
1915 | 1914 | </p>
|
1916 | 1915 |
|
1917 | 1916 |
|
|
0 commit comments