Skip to content

Commit adc5b55

Browse files
griesemergopherbot
authored andcommitted
spec: adjust for-range prose to include iterator functions where missing
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 <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent 69e7b2b commit adc5b55

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: doc/go_spec.html

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Language version go1.23 (June 12, 2024)",
3+
"Subtitle": "Language version go1.23 (June 13, 2024)",
44
"Path": "/ref/spec"
55
}-->
66

@@ -6620,7 +6620,8 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
66206620
<p>
66216621
A "for" statement with a "range" clause
66226622
iterates through all entries of an array, slice, string or map, values received on
6623-
a channel, or integer values from zero to an upper limit [<a href="#Go_1.22">Go 1.22</a>].
6623+
a channel, integer values from zero to an upper limit [<a href="#Go_1.22">Go 1.22</a>],
6624+
or values passed to an iterator function's yield function [<a href="#Go_1.23">Go 1.23</a>].
66246625
For each entry it assigns <i>iteration values</i>
66256626
to corresponding <i>iteration variables</i> if present and then executes the block.
66266627
</p>
@@ -6633,11 +6634,15 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
66336634
The expression on the right in the "range" clause is called the <i>range expression</i>,
66346635
its <a href="#Core_types">core type</a> must be
66356636
an array, pointer to an array, slice, string, map, channel permitting
6636-
<a href="#Receive_operator">receive operations</a>, or an integer.
6637+
<a href="#Receive_operator">receive operations</a>, an integer, or
6638+
a function with specific signature (see below).
66376639
As with an assignment, if present the operands on the left must be
66386640
<a href="#Address_operators">addressable</a> or map index expressions; they
6639-
denote the iteration variables. If the range expression is a channel or integer,
6640-
at most one iteration variable is permitted, otherwise there may be up to two.
6641+
denote the iteration variables.
6642+
If the range expression is a function, the maximum number of iteration variables depends on
6643+
the function signature.
6644+
If the range expression is a channel or integer, at most one iteration variable is permitted;
6645+
otherwise there may be up to two.
66416646
If the last iteration variable is the <a href="#Blank_identifier">blank identifier</a>,
66426647
the range clause is equivalent to the same clause without that identifier.
66436648
</p>
@@ -8676,6 +8681,12 @@ <h4 id="Go_1.22">Go 1.22</h4>
86768681
</li>
86778682
</ul>
86788683

8684+
<h4 id="Go_1.23">Go 1.23</h4>
8685+
<ul>
8686+
<li>A "for" statement with <a href="#For_range">"range" clause</a> accepts an iterator
8687+
function as range expression.
8688+
</li>
8689+
</ul>
86798690
<h3 id="Type_unification_rules">Type unification rules</h3>
86808691

86818692
<p>

0 commit comments

Comments
 (0)