On Wed, Nov 11, 2020 at 7:42 AM 'Axel Wagner' via golang-nuts <golang-nuts@googlegroups.com> wrote: > > https://play.golang.org/p/qTBiAdR9djt > > `a` is the address of the first element of `l`. > `b` is the address of the first element of `l[0]`, which is of type > `[]interface{}` after the assignment. > > Both `l` and `l[0]` refer to the same underlying array, so their first > elements have the same address. > > In practice, you probably want to walk the value with a depth-first search > and use `reflect` to extract the addresses and check for slices and the like > and use a `map[reflect.Value]bool` with pointers to keep track which values > you've already seen. The code isn't trivial enough for me to just write it > down at the moment, but once the idea is clear, it should be doable.
It might help to look at the implementation of reflect.DeepEqual, which uses this approach to avoid infinite recursion on memory cycles. 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXPVR0V4e_SRfU%3DWmPjnnqzBbqLtP4-gZE3X74skY8sXA%40mail.gmail.com.