*(Thanks a lot for all your help Val!)*

One last question, which I wasn't able to find myself from
https://blog.golang.org/go-maps-in-action

Since a map is a pointer, for any function that take map as a parameter,
or function like,

 func (s set) Something(xxx)

Does it means the map values can be changed inside the function?

If yes, what's the proper way to declare it so as to make sure the values
cannot be changed inside the function?

Thanks, and sorry if the question seems too dumb.


---------- Forwarded message ----------
From: Valentin Deleplace @gmail.com
Date: Fri, Jun 24, 2016 at 2:11 AM
Subject: Re: [go-nuts] How to init a global map
To: Tong Sun @gmail.com

No penalty, passing a map around never copies the values.
But a "pointer to a pointer" receiver is not strictly the same as a pointer
receiver.
Le 24 juin 2016 02:19, "Tong Sun" a écrit :

>
> On Thu, Jun 23, 2016 at 6:54 PM, Val  wrote:
>
> Even in OO style (e.g. java), you would not be able to write
>>  Set s = null;
>>  s.init( list(1,2,3) );
>>
>> This is (more or less) the same problem with value receiver... the
>> "constructor-like" idiom in go is a function NewSet, not a method :
>
>  https://play.golang.org/p/_n56yMhlRt
>
>
> * Now* I understand the reason behind such idiom in go. Yep, everything
> makes sense now.
>
> Thanks a lot for the clear explanation.
> That really helps.
>
> Hmm... wait,
>
> map is a reference type
>
>
> Does that means that, this function
>
>     func (s set) Has(a string) bool { _, ok := s[a]; return ok }
>
> is exactly the same as the following?
>
>     func (s *set) Has(a string) bool { _, ok := (*s)[a]; return ok }
>
> I.e., even the set is super super big, there is no pass-by-value penalty
> in the first version?
>
> Thx
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to