I'm trying to solve the slices exercise. My current solution is
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
picture := make([][]uint8, dy)
x := dx
for iy := 0; iy < dy; iy++ {
picture[iy] = make([]uint8, dx)
for ix := 0; ix < dx; ix++ {
x = (x+dy)/2
picture[iy][ix] = uint8(x)
}
}
return picture
}
func main() {
pic.Show(Pic(1,2))
}
But I'm getting the following error
tmp/sandbox931798243/main.go:23: cannot use Pic(1, 2) (type [][]uint8) as type func(int, int) [][]uint8 in argument to pic.Show
What am I doing wrong? Might that be a bug with the sandbox?
pic.Show takes a single argument of type func(int, int) [][]uint8 - you need to pass it a function. You're passing the result of executing a func(int, int) [][]uint8, i.e. a [][]uint8. What you want would be:
pic.Show(Pic)
Passing in your function Pic itself, which meets the requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With