Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(965)

Delta Between Two Patch Sets: 2014/static-analysis/demo.go

Issue 172590043: code review 172590043: 2014/static-analysis: add slides for gomeetup presentation. (Closed)
Left Patch Set: diff -r 1a303e2eaf127ae0a75d5998b44f719d8f3e6176 https://code.google.com/p/go.talks Created 9 years, 4 months ago
Right Patch Set: diff -r 1a303e2eaf127ae0a75d5998b44f719d8f3e6176 https://code.google.com/p/go.talks Created 9 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « 2014/static-analysis.slide ('k') | 2014/static-analysis/demoscript » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package main 1 package main
2 2
3 import "fmt" 3 import "fmt"
4 4
5 type Tip int 5 type Leaf int
6 6
7 func (l Tip) Sum() int { return int(l) } 7 func (l Leaf) Sum() int { return int(l) }
8 func (l Tip) String() string { return fmt.Sprintf("%d", l) } 8 func (l Leaf) String() string { return fmt.Sprintf("%d", l) }
9 9
10 type Branch struct{ left, rhs Shrub } 10 type Branch struct{ left, rhs Tree }
11 11
12 func (b *Branch) Sum() int { return b.left.Sum() + b.rhs.Sum() } 12 func (b *Branch) Sum() int { return b.left.Sum() + b.rhs.Sum() }
13 func (b *Branch) String() string { return fmt.Sprintf("(%s, %s)", b.left, b.rhs) } 13 func (b *Branch) String() string { return fmt.Sprintf("(%s, %s)", b.left, b.rhs) }
14 14
15 type Shrub interface { 15 type Tree interface {
16 Sum() int 16 Sum() int
17 } 17 }
18 18
19 func main() { 19 func main() {
20 » var tree Shrub = Tip(42) 20 » var tree Tree = Leaf(42)
21 fmt.Println(tree.Sum()) 21 fmt.Println(tree.Sum())
22 22
23 if unknown { 23 if unknown {
24 » » tree = &Branch{tree, Tip(123)} 24 » » tree = &Branch{tree, Leaf(123)}
25 } 25 }
26 fmt.Println(tree.Sum()) 26 fmt.Println(tree.Sum())
27 fmt.Println(tree) 27 fmt.Println(tree)
28 } 28 }
29 29
30 var unknown bool 30 var unknown bool
31 31
32 // 32 //
33 33
34 func _() { 34 func _() {
35 type Answer struct{ right bool } 35 type Answer struct{ right bool }
36 var x struct { 36 var x struct {
37 Answer 37 Answer
38 Branch 38 Branch
39 } 39 }
40 fmt.Println(x.right) 40 fmt.Println(x.right)
41 } 41 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b