]> Cypherpunks repositories - gostls13.git/commitdiff
doc: fix typos in laws_of_reflection article, add copyright notice.
authorJohan Euphrosine <proppy@google.com>
Wed, 7 Mar 2012 00:24:00 +0000 (11:24 +1100)
committerAndrew Gerrand <adg@golang.org>
Wed, 7 Mar 2012 00:24:00 +0000 (11:24 +1100)
Update #2547.

R=golang-dev, minux.ma, r, r, adg
CC=golang-dev
https://golang.org/cl/5755051

doc/articles/laws_of_reflection.html
doc/articles/laws_of_reflection.tmpl
doc/progs/interface.go
doc/progs/interface2.go

index 4df70e0d2cbac7bf1d8af3c829878f972483cbfb..37eb96bb6b02a04bb95e856186453fbe2c825548 100644 (file)
@@ -216,7 +216,7 @@ At the basic level, reflection is just a mechanism to examine the
 type and value pair stored inside an interface variable. To get
 started, there are two types we need to know about in
 <a href="http://golang.org/pkg/reflect">package reflect</a>:
-<a href="http://golang.org/pkg/reflect/#Type">Type</a>and
+<a href="http://golang.org/pkg/reflect/#Type">Type</a> and
 <a href="http://golang.org/pkg/reflect/#Value">Value</a>. Those two types
 give access to the contents of an interface variable, and two
 simple functions, called <code>reflect.TypeOf</code> and
@@ -356,7 +356,7 @@ reflection object contains a value of a user-defined integer type,
 as in
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f3/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f3/` `/STOP/`}}
 -->    type MyInt int
     var x MyInt = 7
     v := reflect.ValueOf(x)</pre>
@@ -395,7 +395,7 @@ func (v Value) Interface() interface{}
 As a consequence we can say
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f3b/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f3b/` `/STOP/`}}
 -->    y := v.Interface().(float64) // y will have type float64.
     fmt.Println(y)</pre>
 
@@ -415,7 +415,7 @@ the <code>Interface</code> method to the formatted print
 routine:
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f3c/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f3c/` `/STOP/`}}
 -->    fmt.Println(v.Interface())</pre>
 
 <p>
@@ -518,7 +518,7 @@ determined by whether the reflection object holds the original
 item. When we say
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f6/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f6/` `/STOP/`}}
 -->    var x float64 = 3.4
     v := reflect.ValueOf(x)</pre>
 
@@ -577,7 +577,7 @@ and then create a reflection value that points to it, called
 <code>p</code>.
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f7/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f7/` `/STOP/`}}
 -->    var x float64 = 3.4
     p := reflect.ValueOf(&amp;x) // Note: take the address of x.
     fmt.Println(&#34;type of p:&#34;, p.Type())
@@ -601,7 +601,7 @@ and save the result in a reflection <code>Value</code> called
 <code>v</code>:
 </p>
 
-<pre><!--{{code "progs/interface2.go" `/START f7b/` `/START/`}}
+<pre><!--{{code "progs/interface2.go" `/START f7b/` `/STOP/`}}
 -->    v := p.Elem()
     fmt.Println(&#34;settability of v:&#34;, v.CanSet())</pre>
 
@@ -676,10 +676,7 @@ objects.
         f := s.Field(i)
         fmt.Printf(&#34;%d: %s %s = %v\n&#34;, i,
             typeOfT.Field(i).Name, f.Type(), f.Interface())
-    }
-    s.Field(0).SetInt(77)
-    s.Field(1).SetString(&#34;Sunset Strip&#34;)
-    fmt.Println(&#34;t is now&#34;, t)</pre>
+    }</pre>
 
 <p>
 The output of this program is
index 7db5d6d3b565db961afbc4917b921d5bd9f13a48..d89566f6225ef2b41770ba003eaaccf4e353ae9b 100644 (file)
@@ -184,7 +184,7 @@ At the basic level, reflection is just a mechanism to examine the
 type and value pair stored inside an interface variable. To get
 started, there are two types we need to know about in
 <a href="http://golang.org/pkg/reflect">package reflect</a>:
-<a href="http://golang.org/pkg/reflect/#Type">Type</a>and
+<a href="http://golang.org/pkg/reflect/#Type">Type</a> and
 <a href="http://golang.org/pkg/reflect/#Value">Value</a>. Those two types
 give access to the contents of an interface variable, and two
 simple functions, called <code>reflect.TypeOf</code> and
@@ -301,7 +301,7 @@ reflection object contains a value of a user-defined integer type,
 as in
 </p>
 
-{{code "progs/interface2.go" `/START f3/` `/START/`}}
+{{code "progs/interface2.go" `/START f3/` `/STOP/`}}
 
 <p>
 the <code>Kind</code> of <code>v</code> is still
@@ -337,7 +337,7 @@ func (v Value) Interface() interface{}
 As a consequence we can say
 </p>
 
-{{code "progs/interface2.go" `/START f3b/` `/START/`}}
+{{code "progs/interface2.go" `/START f3b/` `/STOP/`}}
 
 <p>
 to print the <code>float64</code> value represented by the
@@ -355,7 +355,7 @@ the <code>Interface</code> method to the formatted print
 routine:
 </p>
 
-{{code "progs/interface2.go" `/START f3c/` `/START/`}}
+{{code "progs/interface2.go" `/START f3c/` `/STOP/`}}
 
 <p>
 (Why not <code>fmt.Println(v)</code>? Because <code>v</code> is a
@@ -450,7 +450,7 @@ determined by whether the reflection object holds the original
 item. When we say
 </p>
 
-{{code "progs/interface2.go" `/START f6/` `/START/`}}
+{{code "progs/interface2.go" `/START f6/` `/STOP/`}}
 
 <p>
 we pass a <em>copy</em> of <code>x</code> to
@@ -506,7 +506,7 @@ and then create a reflection value that points to it, called
 <code>p</code>.
 </p>
 
-{{code "progs/interface2.go" `/START f7/` `/START/`}}
+{{code "progs/interface2.go" `/START f7/` `/STOP/`}}
 
 <p>
 The output so far is
@@ -526,7 +526,7 @@ and save the result in a reflection <code>Value</code> called
 <code>v</code>:
 </p>
 
-{{code "progs/interface2.go" `/START f7b/` `/START/`}}
+{{code "progs/interface2.go" `/START f7b/` `/STOP/`}}
 
 <p>
 Now <code>v</code> is a settable reflection object, as the output
index 91145401e226888ca10f663614a010dda9bd6b11..c2925d590d5659cb3c5a9566a87059f06cd6a484 100644 (file)
@@ -1,3 +1,9 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file contains the code snippets included in "The Laws of Reflection."
+
 package main
 
 import (
index e2716cf16d3e8ccfe2519004e5478d1719272489..2deba32b464aabbca293376a36eb4799ecf9b6a8 100644 (file)
@@ -1,3 +1,9 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file contains the code snippets included in "The Laws of Reflection."
+
 package main
 
 import (
@@ -39,11 +45,14 @@ func f3() {
        type MyInt int
        var x MyInt = 7
        v := reflect.ValueOf(x)
+       // STOP OMIT
        // START f3b OMIT
        y := v.Interface().(float64) // y will have type float64.
        fmt.Println(y)
+       // STOP OMIT
        // START f3c OMIT
        fmt.Println(v.Interface())
+       // STOP OMIT
        // START f3d OMIT
        fmt.Printf("value is %7.1e\n", v.Interface())
        // STOP OMIT
@@ -69,6 +78,7 @@ func f6() {
        // START f6 OMIT
        var x float64 = 3.4
        v := reflect.ValueOf(x)
+       // STOP OMIT
        // START f6b OMIT
        v.SetFloat(7.1)
        // STOP OMIT
@@ -80,9 +90,11 @@ func f7() {
        p := reflect.ValueOf(&x) // Note: take the address of x.
        fmt.Println("type of p:", p.Type())
        fmt.Println("settability of p:", p.CanSet())
+       // STOP OMIT
        // START f7b OMIT
        v := p.Elem()
        fmt.Println("settability of v:", v.CanSet())
+       // STOP OMIT
        // START f7c OMIT
        v.SetFloat(7.1)
        fmt.Println(v.Interface())
@@ -104,6 +116,7 @@ func f8() {
                fmt.Printf("%d: %s %s = %v\n", i,
                        typeOfT.Field(i).Name, f.Type(), f.Interface())
        }
+       // STOP OMIT
        // START f8b OMIT
        s.Field(0).SetInt(77)
        s.Field(1).SetString("Sunset Strip")