]> Cypherpunks repositories - gostls13.git/commitdiff
spec: adjust for-range prose to include iterator functions where missing
authorRobert Griesemer <gri@golang.org>
Thu, 13 Jun 2024 17:57:12 +0000 (10:57 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 13 Jun 2024 20:48:21 +0000 (20:48 +0000)
Also add a missing table entry to the language versions section in the
appendix.

Fixes #67977.

Change-Id: I1f98abbbcc34a4ff31f390752635435eaf6120b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/592595
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

doc/go_spec.html

index c1d3360ef67e04b0f924acd4bb348f386f881653..b5b7f15bbd369b46e7e641f65d97a42f199b87a8 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Language version go1.23 (June 12, 2024)",
+       "Subtitle": "Language version go1.23 (June 13, 2024)",
        "Path": "/ref/spec"
 }-->
 
@@ -6620,7 +6620,8 @@ In that case, the example above prints
 <p>
 A "for" statement with a "range" clause
 iterates through all entries of an array, slice, string or map, values received on
-a channel, or integer values from zero to an upper limit [<a href="#Go_1.22">Go 1.22</a>].
+a channel, integer values from zero to an upper limit [<a href="#Go_1.22">Go 1.22</a>],
+or values passed to an iterator function's yield function [<a href="#Go_1.23">Go 1.23</a>].
 For each entry it assigns <i>iteration values</i>
 to corresponding <i>iteration variables</i> if present and then executes the block.
 </p>
@@ -6633,11 +6634,15 @@ RangeClause = [ ExpressionList "=" | IdentifierList ":=" ] "range" Expression .
 The expression on the right in the "range" clause is called the <i>range expression</i>,
 its <a href="#Core_types">core type</a> must be
 an array, pointer to an array, slice, string, map, channel permitting
-<a href="#Receive_operator">receive operations</a>, or an integer.
+<a href="#Receive_operator">receive operations</a>, an integer, or
+a function with specific signature (see below).
 As with an assignment, if present the operands on the left must be
 <a href="#Address_operators">addressable</a> or map index expressions; they
-denote the iteration variables. If the range expression is a channel or integer,
-at most one iteration variable is permitted, otherwise there may be up to two.
+denote the iteration variables.
+If the range expression is a function, the maximum number of iteration variables depends on
+the function signature.
+If the range expression is a channel or integer, at most one iteration variable is permitted;
+otherwise there may be up to two.
 If the last iteration variable is the <a href="#Blank_identifier">blank identifier</a>,
 the range clause is equivalent to the same clause without that identifier.
 </p>
@@ -8676,6 +8681,12 @@ integer values from zero to an upper limit.
 </li>
 </ul>
 
+<h4 id="Go_1.23">Go 1.23</h4>
+<ul>
+<li>A "for" statement with <a href="#For_range">"range" clause</a> accepts an iterator
+function as range expression.
+</li>
+</ul>
 <h3 id="Type_unification_rules">Type unification rules</h3>
 
 <p>