Thank you very much. All clear now. On Friday, 31 July 2020 12:09:21 UTC-4, Ian Lance Taylor wrote: > > On Fri, Jul 31, 2020 at 8:47 AM ____ <[email protected] <javascript:>> > wrote: > > > > I would appreciate it if someone could help me understand what exactly > I'm doing in the code below. My experience with Go spans a few weekends in > total so please bear with the naiveté of my question. > > > > When I do this > > > > https://play.golang.org/p/rQvmZEqq8tp > > > > the factory and the gadget share the same specs. When I do this > > > > https://play.golang.org/p/-Gi5N-kpKFq > > > > they don't. > > > > Question: What is the proper way to reason about this code? > > > > I'm mostly looking for an efficient mental model that makes an expert go > "of course...", because I've been trying to track references and pointers > in my head with no success. > > A slice is a struct that contains a pointer to an underlying array. > When you change a slice, you change the pointer. When you change an > element of a slice, you change an element of the underlying array. > > It may help to read https://blog.golang.org/slices-intro. > > Ian >
-- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e51935d8-d94f-42c8-9316-b780305ed098o%40googlegroups.com.
