On Fri, Jul 31, 2020 at 8:47 AM ____ <[email protected]> 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/CAOyqgcVKgFJ6mC0GcxOL2pENFFBChJM%3DwEg5UYk5-zZcy67mTA%40mail.gmail.com.
