Jason, The Go specification "Length and capacity" section defines the len built-in function.
Peter On Tuesday, February 6, 2024 at 11:36:21 PM UTC-5 peterGo wrote: > 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 > > On Tuesday, February 6, 2024 at 10:34:07 PM UTC-5 peterGo wrote: > >> 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 >> >> On Tuesday, February 6, 2024 at 8:41:38 PM UTC-5 Jason E. Aten wrote: >> >>> 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 <https://go.dev/ref/spec#Length_and_capacity>, 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. >>> >> -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8b5ba931-2782-4538-bac2-78c5be735e33n%40googlegroups.com.