]> Cypherpunks repositories - gostls13.git/commitdiff
fix a couple of typos.
authorRob Pike <r@golang.org>
Thu, 12 Nov 2009 19:05:20 +0000 (11:05 -0800)
committerRob Pike <r@golang.org>
Thu, 12 Nov 2009 19:05:20 +0000 (11:05 -0800)
add a mention of range to the tutorial.
change tutorial's title.

R=rsc
CC=golang-dev
https://golang.org/cl/152098

doc/go_spec.html
doc/go_tutorial.html
doc/go_tutorial.txt

index 203f036a8236ed8e3393ce10c2e0c1867213f4df..bd98c42903d7a35412f5019084d63c42dde001f5 100644 (file)
@@ -3010,7 +3010,7 @@ yields a function value representing <code>Mv</code> with signature
 </p>
 
 <pre>
-func (tv *T, f int) int
+func (tv *T, a int) int
 </pre>
 
 <p>
index 77ceb354190e7ab32e6e066a8ae2fc00238b15f3..bbd87bb61c2b2831a26094ba4dacd3f3157bcfc7 100644 (file)
@@ -1,4 +1,4 @@
-<!-- Let's Go -->
+<!-- A Tutorial for the Go Programming Language -->
 <h2>Introduction</h2>
 <p>
 This document is a tutorial introduction to the basics of the Go programming
@@ -340,6 +340,24 @@ The built-in function <code>len()</code>, which returns number of elements,
 makes its first appearance in <code>sum</code>.  It works on strings, arrays,
 slices, maps, and channels.
 <p>
+By the way, another thing that works on strings, arrays, slices, maps
+and channels is the <code>range</code> clause on <code>for</code> loops.  Instead of writing
+<p>
+<pre>
+    for i := 0; i < len(a); i++ { ... }
+</pre>
+<p>
+to loop over the elements of a slice (or map or ...) , we could write
+<p>
+<pre>
+    for i, v := range a { ... }
+</pre>
+<p>
+This assigns <code>i</code> to the index and <code>v</code> to the value of the successive
+elements of the target of the range.   See
+<a href='/doc/effective_go.html'>Effective Go</a>
+for more examples of its use.
+<p>
 <p>
 <h2>An Interlude about Allocation</h2>
 <p>
@@ -511,7 +529,7 @@ exported factory to use is <code>Open</code>:
 </pre>
 <p>
 There are a number of new things in these few lines.  First, <code>Open</code> returns
-multiple values, an <code>File</code> and an error (more about errors in a moment).
+multiple values, a <code>File</code> 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
index 8e2effd33f06cc3b66ae6ccc0f01302b4aa549df..8d57dffb6fc0af0d3c20908f1b388bfefa92c16a 100644 (file)
@@ -1,4 +1,4 @@
-<!-- Let's Go -->
+<!-- A Tutorial for the Go Programming Language -->
 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
+<a href='/doc/effective_go.html'>Effective Go</a>
+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