Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-11 Thread Sean Liao
Perhaps this section of the spec will help: https://golang.org/ref/spec#Method_declarations > The type of a method is the type of a function with the receiver as first argument So there's only a single copy of the function code, but the argument passed to it is copied >From your original

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-11 Thread E Z
Thank you so much. Your explanation makes my understanding of this problem more and more clear. However, since I have been a C programmer for a long time, I still don't understand the implementation of the function variable in Golang very well. I think I need to do some inspection about

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-11 Thread Brian Candler
On Wednesday, 11 August 2021 at 09:23:44 UTC+1 Brian Candler wrote: > v := Zoo{} > Display1(v) # v is copied > vp := > Display2(vp) # vp is copied > > Correction: vp := or vp := {...} > These are identical, consistent behaviours. > > So now onto "pointer to function". You are

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-11 Thread Brian Candler
On Tuesday, 10 August 2021 at 22:50:00 UTC+1 lege...@gmail.com wrote: > And I'm still a little confused here, you know when we use the struct > method directly, it is only when the function is called that the type of > receiver determines whether the passed struct is a pointer or a copied >

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread 'Dan Kortschak' via golang-nuts
On Tue, 2021-08-10 at 15:54 -0700, E Z wrote: > I quite agree with your above conclusion, and the test results also > prove it. That seems to be the way it's designed right now, but what > I find a little hard to understand here is why it's not designed as > "The pointer to function assignment

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread E Z
" The pointer to function assignment captures the current receiver." I quite agree with your above conclusion, and the test results also prove it. That seems to be the way it's designed right now, but what I find a little hard to understand here is why it's not designed as "The pointer to

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread burak serdar
On Tue, Aug 10, 2021 at 3:50 PM E Z wrote: > It works when I changed the code as your suggested. That's great, thanks. > > And I'm still a little confused here, you know when we use the struct > method directly, it is only when the function is called that the type of > receiver determines

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread 'Dan Kortschak' via golang-nuts
On Tue, 2021-08-10 at 14:50 -0700, E Z wrote: > It works when I changed the code as your suggested. That's great, > thanks. > > And I'm still a little confused here, you know when we use the struct > method directly, it is only when the function is called that the type > of receiver determines

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread E Z
It works when I changed the code as your suggested. That's great, thanks. And I'm still a little confused here, you know when we use the struct method directly, it is only when the function is called that the type of receiver determines whether the passed struct is a pointer or a copied value.

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread burak serdar
On Tue, Aug 10, 2021 at 12:01 PM E Z wrote: > I feel confused when I use the function pointer which point to the struct > method. Here is the test code: > > /*** > package main > > type Zoo struct { > Animal string > } > > func (z Zoo) Display(){ > fmt.Printf("Current animal is:%s\n",

[go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread E Z
I feel confused when I use the function pointer which point to the struct method. Here is the test code: /*** package main type Zoo struct { Animal string } func (z Zoo) Display(){ fmt.Printf("Current animal is:%s\n", z.Animal) } func main(){ gz := { Animal: "Monkey",