Skip to content

spec: the introduction to 'For statements with range clause' fails to mention range-over-func #67977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gazerro opened this issue Jun 13, 2024 · 4 comments
Assignees
Labels
Documentation Issues describing a change to documentation.
Milestone

Comments

@gazerro
Copy link
Contributor

gazerro commented Jun 13, 2024

The introduction of the paragraph on For statements with range clause fails to mention the range over function:

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]. [...]

and also

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.

@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gazerro
Copy link
Contributor Author

gazerro commented Jun 13, 2024

Note also that the statement

If the range expression is a channel or integer, at most one iteration variable is permitted, otherwise there may be up to two.

is not accurate, as func(func() bool) does not allow iteration variables, and func(func(V) bool) allows at most one iteration variable.

@griesemer
Copy link
Contributor

Thanks for this. Update forthcoming.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/592595 mentions this issue: spec: adjust for-range prose to include iterator functions where missing

@griesemer griesemer added the Documentation Issues describing a change to documentation. label Jun 13, 2024
@griesemer griesemer added this to the Go1.23 milestone Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation.
Projects
None yet
Development

No branches or pull requests

4 participants