Limitation in pic.Show?

251 views
Skip to first unread message

aurelien

unread,
Aug 9, 2015, 4:25:42 AM8/9/15
to golang-nuts
Hello Gophers!

Working on the http://tour.golang.org/moretypes/14 , I have tried to go a bit more fare by implementing one more int.

But at this time I don't understand if the shell return says it is not possible or if I have not well write the code.


 19 package main
 20 
 21 import "golang.org/x/tour/pic"
 22 
 23 func Pic(dx, dy, dz int) [][][]uint8 {
 24   pic := make([][][]uint8, dy)
 25   for i := range pic {
 26     pic[i] = make([][]uint8, dx)
 27     for j := range pic {
 28       pic[j] = make([][]uint8, dz)
 29       for k := range pic {
 30         pic[i][j][k] = uint8(((j ^ i ^ k) ^ 10) * (10 ^ (i * j * k)))
 31       }
 32     }
 33   }
 34   return pic
 35 }
 36 func main() {
 37   pic.Show(Pic)
 38 }


:!go run exo-test-slice.go
# command-line-arguments
./exo-test-slice.go:37: cannot use Pic (type func(int, int, int) [][][]uint8) as type func(int, int) [][]uint8 in argument to pic.Show

shell returned 2



AD

aurelien

unread,
Aug 9, 2015, 4:32:42 AM8/9/15
to golang-nuts
Sounds to be a limitation in pic.go
https://github.com/golang/tour/blob/master/pic/pic.go 

Justin Israel

unread,
Aug 9, 2015, 4:39:26 AM8/9/15
to aurelien, golang-nuts
On Sun, Aug 9, 2015 at 8:32 PM aurelien <aurelien....@gmail.com> wrote:
Sounds to be a limitation in pic.go
https://github.com/golang/tour/blob/master/pic/pic.go 

It isn't a limitation. It is the fact that you are importing a "pic" library in order to follow the tour example, and "pic.Show()" is a function that takes a specific type of argument. Your error reports the problem:

 cannot use Pic (type func(int, int, int) [][][]uint8) as type func(int, int) [][]uint8 in argument to pic.Show

That is telling you that pic.Show() expects a function that takes 2 int parameters, and returns a 2 dimensional slice (a slice of uint8 slices). Now, in your code you are trying to expand the functionality of your own function by introducing a 3rd dimension to your image. But that doesn't change the fact that pic.Show() still requires the original function type.
 
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

aurelien

unread,
Aug 9, 2015, 5:00:26 AM8/9/15
to golang-nuts
Hi Justin,

Yes that is what I was understanding by continuing to works on it ... and I was trying to bring that 3rd dimension to pic by modifying it directly and try to bring it back to part of the code by import this version of pic.go.


But I do not find the way to make the exo-test-slice.go use my pic.go


:!go run exo-test-slice.go
exo-test-slice.go:21:8: cannot find package "github.com/4ur3l13n/go/blob/master/pic" in any of:
        /usr/lib/go/src/github.com/4ur3l13n/go/blob/master/pic (from $GOROOT)
        /home/aurelien/go/src/github.com/4ur3l13n/go/blob/master/pic (from $GOPATH)

shell returned 1


AD

Justin Israel

unread,
Aug 9, 2015, 7:05:18 AM8/9/15
to aurelien, golang-nuts


On Sun, 9 Aug 2015 9:00 PM aurelien <aurelien....@gmail.com> wrote:

Hi Justin,

Yes that is what I was understanding by continuing to works on it ... and I was trying to bring that 3rd dimension to pic by modifying it directly and try to bring it back to part of the code by import this version of pic.go.

https://github.com/4ur3l13n/go/blob/master/pic/pic.go

But I do not find the way to make the exo-test-slice.go use my pic.go

:!go run exo-test-slice.go

exo-test-slice.go:21:8: cannot find package "github.com/4ur3l13n/go/blob/master/pic" in any of:

        /usr/lib/go/src/github.com/4ur3l13n/go/blob/master/pic (from $GOROOT)

        /home/aurelien/go/src/github.com/4ur3l13n/go/blob/master/pic (from $GOPATH)

shell returned 1


If you are trying to use that modified version  of the pic package, then it would be expected to have an import path like:

github.com/4ur3l13n/go/pic

And physically live here in your GOPATH:

/home/aurelien/go/src/github.com/4ur3l13n/go/pic

aurelien

unread,
Aug 9, 2015, 8:17:38 AM8/9/15
to golang-nuts, aurelien....@gmail.com
Thanks for your help! 
Reply all
Reply to author
Forward
0 new messages