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 <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>
This commit is contained in:
Robert Griesemer 2024-06-13 10:57:12 -07:00 committed by Gopher Robot
parent 69e7b2bcd6
commit adc5b559db
1 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<!--{ <!--{
"Title": "The Go Programming Language Specification", "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" "Path": "/ref/spec"
}--> }-->
@ -6620,7 +6620,8 @@ In that case, the example above prints
<p> <p>
A "for" statement with a "range" clause A "for" statement with a "range" clause
iterates through all entries of an array, slice, string or map, values received on 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> For each entry it assigns <i>iteration values</i>
to corresponding <i>iteration variables</i> if present and then executes the block. to corresponding <i>iteration variables</i> if present and then executes the block.
</p> </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>, 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 its <a href="#Core_types">core type</a> must be
an array, pointer to an array, slice, string, map, channel permitting 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 As with an assignment, if present the operands on the left must be
<a href="#Address_operators">addressable</a> or map index expressions; they <a href="#Address_operators">addressable</a> or map index expressions; they
denote the iteration variables. If the range expression is a channel or integer, denote the iteration variables.
at most one iteration variable is permitted, otherwise there may be up to two. 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>, 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. the range clause is equivalent to the same clause without that identifier.
</p> </p>
@ -8676,6 +8681,12 @@ integer values from zero to an upper limit.
</li> </li>
</ul> </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> <h3 id="Type_unification_rules">Type unification rules</h3>
<p> <p>