mirror of https://github.com/tinygo-org/tinygo.git
Ayke van Laethem
6 years ago
2 changed files with 35 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||
package main |
|||
|
|||
func main() { |
|||
l := 5 |
|||
foo := []int{1, 2, 4, 5} |
|||
bar := make([]int, l-2, l) |
|||
printslice("foo", foo) |
|||
printslice("bar", bar) |
|||
printslice("foo[1:2]", foo[1:2]) |
|||
println("sum foo:", sum(foo)) |
|||
println("copy foo -> bar:", copy(bar, foo)) |
|||
printslice("bar", bar) |
|||
} |
|||
|
|||
func printslice(name string, s []int) { |
|||
print(name, ": len=", len(s), " cap=", cap(s), " data:") |
|||
for _, n := range s { |
|||
print(" ", n) |
|||
} |
|||
println() |
|||
} |
|||
|
|||
func sum(l []int) int { |
|||
sum := 0 |
|||
for _, n := range l { |
|||
sum += n |
|||
} |
|||
return sum |
|||
} |
@ -0,0 +1,6 @@ |
|||
foo: len=4 cap=4 data: 1 2 4 5 |
|||
bar: len=3 cap=5 data: 0 0 0 |
|||
foo[1:2]: len=1 cap=3 data: 2 |
|||
sum foo: 12 |
|||
copy foo -> bar: 3 |
|||
bar: len=3 cap=5 data: 1 2 4 |
Loading…
Reference in new issue