From: Rob Pike Date: Thu, 12 Nov 2009 19:05:20 +0000 (-0800) Subject: fix a couple of typos. X-Git-Tag: weekly.2009-11-12~5 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cf16443c69ff45db8b9493a92bec0812111b1c78;p=gostls13.git fix a couple of typos. add a mention of range to the tutorial. change tutorial's title. R=rsc CC=golang-dev https://golang.org/cl/152098 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 203f036a82..bd98c42903 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -3010,7 +3010,7 @@ yields a function value representing Mv with signature

-func (tv *T, f int) int
+func (tv *T, a int) int
 

diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index 77ceb35419..bbd87bb61c 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -1,4 +1,4 @@ - +

Introduction

This document is a tutorial introduction to the basics of the Go programming @@ -340,6 +340,24 @@ The built-in function len(), which returns number of elements, makes its first appearance in sum. It works on strings, arrays, slices, maps, and channels.

+By the way, another thing that works on strings, arrays, slices, maps +and channels is the range clause on for loops. Instead of writing +

+

+    for i := 0; i < len(a); i++ { ... }
+
+

+to loop over the elements of a slice (or map or ...) , we could write +

+

+    for i, v := range a { ... }
+
+

+This assigns i to the index and v to the value of the successive +elements of the target of the range. See +Effective Go +for more examples of its use. +

An Interlude about Allocation

@@ -511,7 +529,7 @@ exported factory to use is Open:

There are a number of new things in these few lines. First, Open returns -multiple values, an File and an error (more about errors in a moment). +multiple values, a File and an error (more about errors in a moment). We declare the multi-value return as a parenthesized list of declarations; syntactically they look just like a second parameter list. The function diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt index 8e2effd33f..8d57dffb6f 100644 --- a/doc/go_tutorial.txt +++ b/doc/go_tutorial.txt @@ -1,4 +1,4 @@ - + Introduction ---- @@ -264,6 +264,20 @@ The built-in function "len()", which returns number of elements, makes its first appearance in "sum". It works on strings, arrays, slices, maps, and channels. +By the way, another thing that works on strings, arrays, slices, maps +and channels is the "range" clause on "for" loops. Instead of writing + + for i := 0; i < len(a); i++ { ... } + +to loop over the elements of a slice (or map or ...) , we could write + + for i, v := range a { ... } + +This assigns "i" to the index and "v" to the value of the successive +elements of the target of the range. See +Effective Go +for more examples of its use. + An Interlude about Allocation ---- @@ -391,7 +405,7 @@ exported factory to use is "Open": --PROG progs/file.go /func.Open/ /^}/ There are a number of new things in these few lines. First, "Open" returns -multiple values, an "File" and an error (more about errors in a moment). +multiple values, a "File" and an error (more about errors in a moment). We declare the multi-value return as a parenthesized list of declarations; syntactically they look just like a second parameter list. The function