From: griesemer Date: Thu, 19 Oct 2017 18:48:54 +0000 (-0700) Subject: spec: remove vestiges referring to iotas being incremented X-Git-Tag: go1.10beta1~656 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=85177f42767fdd6c245dcd0ba0e70e0427600f3f;p=gostls13.git 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 Reviewed-by: Rob Pike Reviewed-by: Matthew Dempsky --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 3cb221ce6c..2309ce47fe 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1837,7 +1837,7 @@ const u, v float32 = 0, 3 // u = 0.0, v = 3.0

Within a parenthesized const 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:

-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 << iota  // a == 1
-	b = 1 << iota  // b == 2
-	c = 3          // c == 3  (iota is not used but still incremented)
-	d = 1 << iota  // d == 8
+const (
+	a = 1 << iota  // a == 1  (iota == 0)
+	b = 1 << iota  // b == 2  (iota == 1)
+	c = 3          // c == 3  (iota == 2, unused)
+	d = 1 << 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
 

-Within an ExpressionList, the value of each iota is the same because -it is only incremented after each ConstSpec: +By definition, multiple uses of iota in the same ConstSpec all have the same value:

 const (
-	bit0, mask0 = 1 << iota, 1<<iota - 1  // bit0 == 1, mask0 == 0
-	bit1, mask1                           // bit1 == 2, mask1 == 1
-	_, _                                  // skips iota == 2
-	bit3, mask3                           // bit3 == 8, mask3 == 7
+	bit0, mask0 = 1 << iota, 1<<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)
 )
 

-This last example exploits the implicit repetition of the -last non-empty expression list. +This last example exploits the implicit repetition +of the last non-empty expression list.