forked from cosmos72/gomacro
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (65 loc) · 1.45 KB
/
main.go
File metadata and controls
74 lines (65 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// empty file. stops "go build" from complaining that
// no buildable files are in the directory "examples"
package main
import (
"fmt"
"io"
"os"
r "reflect"
)
func main() {
// run_for_nested()
run_interface_method_to_closure()
run_struct_method_to_closure()
}
type stringer interface{ String() string }
type Box struct{ value int }
func (b *Box) Value() int {
return b.value
}
func run_struct_method_to_closure() {
var b *Box
fmt.Printf("%v %T\n", b, b)
function := (*Box).Value
fmt.Printf("%v %T\n", function, function)
closure := b.Value
fmt.Printf("%v %T\n", closure, closure)
}
func run_interface_method_to_closure() {
var s stringer
fmt.Printf("%v %T\n", s, s)
function := stringer.String
fmt.Printf("%v %T\n", function, function)
closure := s.String
fmt.Printf("%v %T\n", closure, closure)
}
func main2() {
var TypeOfInterface = r.TypeOf((*interface{})(nil)).Elem()
p := r.ValueOf(new(interface{}))
i := p.Elem()
c := i.Convert(TypeOfInterface)
fmt.Printf("%v %v\n", p, p.Type())
fmt.Printf("%v %v\n", i, i.Type())
fmt.Printf("%v %v\n", c, c.Type())
/*
defer func() {
fmt.Println(recover())
}()
defer func() {
fmt.Println("foo")
}()
panic("test panic")
*/
// m := [...]int{0x7ffffff: 3}
// fmt.Println(m)
// p := Pair{A: 1, B: true}
// Pair{1, 2} = Pair{}
// var f os.file
// _ = bytes.Buffer{nil, 0}
}
func main1() {
var x io.ReadWriteCloser = os.Stdin
f := io.ReadWriteCloser.Close
f(x)
fmt.Printf("%T\n", f)
}