Is it possible to fix and make the *validSub.Init*([]string{"aa", "bb", "cc"})
works instead? Coming from the OO world, this is a form that I feel more comfort with. Thx. ---------- Forwarded message ---------- From: andrey mirtchovski <mirtchov...@gmail.com> Date: Thu, Jun 23, 2016 at 6:16 PM Subject: Re: [go-nuts] How to init a global map To: Tong Sun <suntong...@gmail.com> if you just want to fix it: https://play.golang.org/p/cL0svI8FU4 On Thu, Jun 23, 2016 at 4:12 PM, Tong Sun <suntong...@gmail.com> wrote: > My mind is not working and I can't find how to fix the following program > (https://play.golang.org/p/oXxUndUSye): > > > package main > > > import ( > "fmt" > ) > > > type set map[string]struct{} > > > var validSub set > > > func init() { > validSub.Init([]string{"aa", "bb", "cc"}) > fmt.Printf("%+v\n", validSub) > } > > > func (s set) Init(slice []string) { > s = make(map[string]struct{}, len(slice)) > for _, s1 := range slice { > s[s1] = struct{}{} > } > } > > > func (s set) Has(a string) bool { _, ok := s[a]; return ok } > > > func main() { > fmt.Println(validSub.Has("aa")) > fmt.Println(validSub.Has("dd")) > } > > > > Please help. > > -- > 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. -- 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.