summaryrefslogtreecommitdiff
path: root/doc/progs/interface2.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-02-12 16:16:25 -0500
committerRuss Cox <rsc@golang.org>2021-02-16 02:07:02 +0000
commit0cb3415154ff354b42db1d65073e9be71abcc970 (patch)
treec88db4651ed4a07dcd1f718654915f0e366f6742 /doc/progs/interface2.go
parent626ef0812739ac7bb527dbdf4b0ed3a436c90901 (diff)
downloadgo-git-0cb3415154ff354b42db1d65073e9be71abcc970.tar.gz
doc: remove all docs not tied to distribution
They have moved to x/website in CL 291693. The docs that are left are the ones that are edited at the same time as development in this repository and are tied to the specific version of Go being developed. Those are: - the language spec - the memory model - the assembler manual - the current release's release notes Change-Id: I437c4d33ada1b1716b1919c3c939c2cacf407e83 Reviewed-on: https://go-review.googlesource.com/c/go/+/291711 Trust: Russ Cox <rsc@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'doc/progs/interface2.go')
-rw-r--r--doc/progs/interface2.go132
1 files changed, 0 insertions, 132 deletions
diff --git a/doc/progs/interface2.go b/doc/progs/interface2.go
deleted file mode 100644
index a541d94e48..0000000000
--- a/doc/progs/interface2.go
+++ /dev/null
@@ -1,132 +0,0 @@
-// 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 (
- "fmt"
- "reflect"
-)
-
-func main() {
- var x float64 = 3.4
- fmt.Println("type:", reflect.TypeOf(x))
- // STOP OMIT
- // TODO(proppy): test output OMIT
-}
-
-// STOP main OMIT
-
-func f1() {
- // START f1 OMIT
- var x float64 = 3.4
- v := reflect.ValueOf(x)
- fmt.Println("type:", v.Type())
- fmt.Println("kind is float64:", v.Kind() == reflect.Float64)
- fmt.Println("value:", v.Float())
- // STOP OMIT
-}
-
-func f2() {
- // START f2 OMIT
- var x uint8 = 'x'
- v := reflect.ValueOf(x)
- fmt.Println("type:", v.Type()) // uint8.
- fmt.Println("kind is uint8: ", v.Kind() == reflect.Uint8) // true.
- x = uint8(v.Uint()) // v.Uint returns a uint64.
- // STOP OMIT
-}
-
-func f3() {
- // START f3 OMIT
- 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
-}
-
-func f4() {
- // START f4 OMIT
- var x float64 = 3.4
- v := reflect.ValueOf(x)
- v.SetFloat(7.1) // Error: will panic.
- // STOP OMIT
-}
-
-func f5() {
- // START f5 OMIT
- var x float64 = 3.4
- v := reflect.ValueOf(x)
- fmt.Println("settability of v:", v.CanSet())
- // STOP OMIT
-}
-
-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
-}
-
-func f7() {
- // START f7 OMIT
- var x float64 = 3.4
- 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())
- fmt.Println(x)
- // STOP OMIT
-}
-
-func f8() {
- // START f8 OMIT
- type T struct {
- A int
- B string
- }
- t := T{23, "skidoo"}
- s := reflect.ValueOf(&t).Elem()
- typeOfT := s.Type()
- for i := 0; i < s.NumField(); i++ {
- f := s.Field(i)
- 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")
- fmt.Println("t is now", t)
- // STOP OMIT
-}
-
-func f9() {
- // START f9 OMIT
- var x float64 = 3.4
- fmt.Println("value:", reflect.ValueOf(x))
- // STOP OMIT
-}