Skip to content

Commit

Permalink
Add slices and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
emacampolo committed Nov 6, 2019
1 parent 1a70270 commit 1939a84
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
Binary file added slides/array.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion slides/pointer/array/array.go
Expand Up @@ -10,7 +10,7 @@ func main() {
friends[1] = "Jack"

if i == 1 {
fmt.Printf("After[%s]\n", friends[1])
fmt.Println(friends[1])
}
}
}
2 changes: 1 addition & 1 deletion slides/pointer/slices/slices.go
Expand Up @@ -8,6 +8,6 @@ func main() {

for i := range friends {
friends = []string{}
fmt.Printf("v[%s]\n", friends[i])
fmt.Println(friends[i])
}
}
Binary file added slides/slice.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions slides/slide.slide
Expand Up @@ -172,6 +172,27 @@ _Bottom_line_: When in doubt, use value semantics

* Arrays

* Arrays

var a [4]int

.image array.png _ 1000

* Slices

s := make([]byte, 5)

.image slice.png 500 1000

* For-range mechanics

// Value semantic of the for range
for i, _ := range c
for _, value := range c

// Pointer semantic of the for range
for i := range c

* Arrays - Value semantics

.play -edit value/array/array.go
Expand Down
2 changes: 1 addition & 1 deletion slides/value/array/array.go
Expand Up @@ -10,7 +10,7 @@ func main() {
friends[1] = "Jack"

if i == 1 {
fmt.Printf("After[%s]\n", v)
fmt.Println(v)
}
}
}
2 changes: 1 addition & 1 deletion slides/value/slices/slices.go
Expand Up @@ -8,6 +8,6 @@ func main() {

for _, v := range friends {
friends = []string{}
fmt.Printf("[%s]\n", v)
fmt.Println(v)
}
}

0 comments on commit 1939a84

Please sign in to comment.