new range over int docs?

397 views
Skip to first unread message

Jason E. Aten

unread,
Feb 6, 2024, 8:41:38 PM2/6/24
to golang-nuts
The release notes https://go.dev/doc/go1.22 refer to the spec here

https://go.dev/ref/spec#For_range

but I do not see any details about the new for i := range 10 statement there.

This is strange. Have the docs simply not been updated yet?

But I do see this oddly out of place statement, where I'm not sure at all what x is referring to in the earlier paragraphs.

"The range expression x is evaluated once before beginning the loop, with one exception: if at most one iteration variable is present and len(x) is constant, the range expression is not evaluated."

This would seem to say that, if x is the integer 10, as in the above example, and if the len(10) is somehow defined (not sure it would be, but a new reader might reasonably assume that an integer has constant length), that the range expression would not be evaluated... which seems very odd. I'm not sure what this sentence is talking about at all really.

peterGo

unread,
Feb 6, 2024, 10:34:07 PM2/6/24
to golang-nuts
Jason,

The Go Programming Language Specification is reference documentation. It is intended to be read very carefully in its entirety.

You are reading a specification dated Version of Aug 2, 2023. The current specification for Go 1.22 is dated as Modified Tue 06 Feb 2024 10:08:15 PM EST.

The specification has always said that len(10) is not somehow defined: "invalid argument: 10 (untyped int constant) for len".

Peter

peterGo

unread,
Feb 6, 2024, 11:36:21 PM2/6/24
to golang-nuts
Jason,

The Go 1.22 specification, in part,

For statements with range clause

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

For an integer value n, the iteration values 0 through n-1 are produced in increasing order. If n <= 0, the loop does not run any iterations.

Peter

peterGo

unread,
Feb 6, 2024, 11:46:35 PM2/6/24
to golang-nuts
Jason,

The Go specification "Length and capacity" section defines the len built-in function.

Peter

Jason E. Aten

unread,
Feb 7, 2024, 1:17:25 AM2/7/24
to peterGo, golang-nuts
On Wed, Feb 7, 2024 at 3:34 AM peterGo <go.pe...@gmail.com> wrote:
You are reading a specification dated Version of Aug 2, 2023. The current specification for Go 1.22 is dated as Modified Tue 06 Feb 2024 10:08:15 PM EST.

Link?   https://go.dev/ref/spec still gives me the Aug 2, 2023 spec, which is what the 1.22 release notes points to.

 

peterGo

unread,
Feb 7, 2024, 4:47:29 AM2/7/24
to golang-nuts
Jason,

The Go 1.22 source code says:

"Subtitle": "Language version go1.22 (Jan 30, 2023)",

Blame

#569 9289b9c gri@*********.*** 2024-01-31 16:40
[release-branch.go1.22] spec: clarify iteration variable type for range over integer
Change-Id: I4f1d220d5922c40a36264df2d0a7bb7cd0756bac

https://cs.opensource.google/go/go/+/release-branch.go1.22:doc/go_spec.html

I consider the Go source code to be the truth.

What are you looking at?

Peter

Rob Pike

unread,
Feb 7, 2024, 7:02:28 AM2/7/24
to peterGo, golang-nuts
Ha ha, someone forgot to change the year. It should read Jan 30, 2024.

That's confusing.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0e4fa760-1259-4b9c-9ff6-b60ba34413ccn%40googlegroups.com.

Brian Candler

unread,
Feb 7, 2024, 7:12:08 AM2/7/24
to golang-nuts
But the main point is, the canonical version published at https://go.dev/ref/spec is still from Aug 2, 2023

peterGo

unread,
Feb 7, 2024, 7:55:52 AM2/7/24
to golang-nuts
Jason,

File an issue with the Go release team to clean up the mess.

Peter

peterGo

unread,
Feb 7, 2024, 10:32:01 AM2/7/24
to golang-nuts
Jason,

As a temporary fix, try


Peter

Jason E. Aten

unread,
Feb 7, 2024, 11:12:05 AM2/7/24
to peterGo, golang-nuts
Thanks Peter.  I see the latest spec at tip.golang.org.

p.s. Go Team: At least in the UK, the page served from    https://go.dev/ref/spec   does not, at the moment, match that of     https://tip.golang.org/ref/spec  , so somebody may need to do an update (if not of origin server, maybe of CDN caches?)


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/qGBpoyf1EB0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/200fefc5-b0c0-4b4d-b876-b98b5795d35an%40googlegroups.com.

Robert Griesemer

unread,
Feb 7, 2024, 12:25:10 PM2/7/24
to Jason E. Aten, peterGo, golang-nuts
Spec is up-to-date at tip, now: https://tip.golang.org/ref/spec
https://golang.org/ref/spec should be updated soon, too.
Apologies for the confusion.
- gri

You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAPNEFAZJqS3tPt0kBbbU6WuvLe0%3DhLqXdsRz9K22HCRGOhi21g%40mail.gmail.com.

Jason E. Aten

unread,
Feb 7, 2024, 12:58:37 PM2/7/24
to Robert Griesemer, golang-nuts
Thanks Robert.  Succeess: I see the latest go1.22 spec now on https://go.dev/ref/spec

Minor nit: As Rob pointed out, the year in the sub-title is off by one. (It says Jan 30, 2023, while almost surely the author of the update meant Jan 30, 2024).

"The Go Programming Language Specification
Language version go1.22 (Jan 30, 2023)" <<<<<<<<<< 2024, no?

Robert Griesemer

unread,
Feb 7, 2024, 2:30:18 PM2/7/24
to Jason E. Aten, golang-nuts
On Wed, Feb 7, 2024 at 9:58 AM Jason E. Aten <j.e....@gmail.com> wrote:
Thanks Robert.  Succeess: I see the latest go1.22 spec now on https://go.dev/ref/spec

Minor nit: As Rob pointed out, the year in the sub-title is off by one. (It says Jan 30, 2023, while almost surely the author of the update meant Jan 30, 2024).
The respective CL is pending submission (https://go.dev/cl/562320). Once submitted it should fix the issue there as well.
Thanks.
- gri

Reply all
Reply to author
Forward
0 new messages