Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread 'Dan Kortschak' via golang-nuts
On Wed, 2023-03-15 at 12:55 -0400, Frank Juedes wrote: > > > Hi Dan, > Thank you very much for your answer, so that's the data structure > behind maps, very interesting. > I had actually thought about using unsafe pointers and then type- > casting, but that is how i would have done it in the

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread Frank Juedes
On 2023-03-15 06:06, Jan Mercl wrote: On Wed, Mar 15, 2023 at 11:03 AM Frank Jüdes wrote: Well, that didn't go very far:https://go.dev/play/p/UtsrRar9J0Q Fails with the messages ./prog.go:15:11: invalid operation: cannot index p_Map (variable of type MAP constrained by DataMap)

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread Brian Candler
Which is also the reason why you can't insert into a nil map - you have to make() one. On Wednesday, 15 March 2023 at 10:58:09 UTC Dan Kortschak wrote: > On Tue, 2023-03-14 at 19:56 -0700, Kurtis Rader wrote: > > Maps are a special-case. You can't pass them "by value" in the sense > > you mean

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread 'Dan Kortschak' via golang-nuts
On Tue, 2023-03-14 at 19:56 -0700, Kurtis Rader wrote: > Maps are a special-case. You can't pass them "by value" in the sense > you mean because a "map" value is a very tiny structure that contains > a pointer to the actual map. The passed value is a pointer to the header, otherwise changes to

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread Jan Mercl
On Wed, Mar 15, 2023 at 11:03 AM Frank Jüdes wrote: > > Well, that didn't go very far: https://go.dev/play/p/UtsrRar9J0Q > Fails with the messages > ./prog.go:15:11: invalid operation: cannot index p_Map (variable of type MAP > constrained by DataMap) > ./prog.go:16:26: cannot range over p_Map

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread Frank Jüdes
Well, that didn't go very far: https://go.dev/play/p/UtsrRar9J0Q Fails with the messages ./prog.go:15:11: invalid operation: cannot index p_Map (variable of type MAP constrained by DataMap) ./prog.go:16:26: cannot range over p_Map (variable of type MAP constrained by DataMap) (MAP has no core

Re: [go-nuts] How to generalize parameters for a function

2023-03-15 Thread Frank Jüdes
Hi Kurtis, good to know that a map will always be "kind of" passed by reference to functions. I have verified that with a short test-program on the playground -> https://go.dev/play/p/HxdgpM-QozM So in the next code-review all those *[maptype] references will be removed. Things are very

Re: [go-nuts] How to generalize parameters for a function

2023-03-14 Thread Kurtis Rader
On Tue, Mar 14, 2023 at 7:07 PM Frank Jüdes wrote: > Thank you very much Ian! > I am using a pointer to the map because i want to pass the map by > reference, not by value. > Those maps can become pretty large and are being handed down through a > couple of function calls and i don't want them

Re: [go-nuts] How to generalize parameters for a function

2023-03-14 Thread Frank Jüdes
Thank you very much Ian! I am using a pointer to the map because i want to pass the map by reference, not by value. Those maps can become pretty large and are being handed down through a couple of function calls and i don't want them to be copied over and over again. I read the document you

Re: [go-nuts] How to generalize parameters for a function

2023-03-14 Thread Ian Lance Taylor
On Tue, Mar 14, 2023 at 6:27 PM Frank Jüdes wrote: > > i still somewhat new with Go and need a little tutoring: I have to create > Excel files, using the excelize package and wrote a little function to store > data from a map[string]int64 into a column within the worksheet: > > // >