From adc5b559dbc7e86e4d8c4265d7da31f97fb0cb59 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 13 Jun 2024 10:57:12 -0700 Subject: [PATCH] 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 Reviewed-by: Robert Griesemer Reviewed-by: Ian Lance Taylor Auto-Submit: Robert Griesemer --- doc/go_spec.html | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index c1d3360ef6..b5b7f15bbd 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -6620,7 +6620,8 @@ In that case, the example above prints

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 [Go 1.22]. +a channel, integer values from zero to an upper limit [Go 1.22], +or values passed to an iterator function's yield function [Go 1.23]. For each entry it assigns iteration values to corresponding iteration variables if present and then executes the block.

@@ -6633,11 +6634,15 @@ RangeClause = [ ExpressionList "=" | IdentifierList ":=" ] "range" Expression . The expression on the right in the "range" clause is called the range expression, its core type must be an array, pointer to an array, slice, string, map, channel permitting -receive operations, or an integer. +receive operations, an integer, or +a function with specific signature (see below). As with an assignment, if present the operands on the left must be addressable 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 blank identifier, the range clause is equivalent to the same clause without that identifier.

@@ -8676,6 +8681,12 @@ integer values from zero to an upper limit. +

Go 1.23

+
    +
  • A "for" statement with "range" clause accepts an iterator +function as range expression. +
  • +

Type unification rules

-- 2.48.1