If the slice is empty, it doesn't reference anything. If it is not empty, &x[0] can be used to identify the slice (potentially also using len/cap, if it's interesting).
On Tue, Nov 10, 2020 at 4:11 AM arpad ryszka <arpad.rys...@gmail.com> wrote: > Hi, > > is there a way to detect the cyclic reference in the following example > somehow? Either via reflection or by other means? My understanding is that > slices cannot be compared with == (unless to nil), or used as keys in maps. > Is there a different way? > > l := []interface{}{"foo"} > l[0] = l > fmt.Println(l) > > or here it is as a playground link: https://play.golang.org/p/T0qZlF8m-vi > > Cheers, > Arpad > > -- > 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/b2cb6b5e-febc-407f-b5b3-d9ca196ce68bn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/b2cb6b5e-febc-407f-b5b3-d9ca196ce68bn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfH5u-u0mu%3DZhkLf%2BhJeTbHjKNNPVJu-6QPmvjN__AtLGA%40mail.gmail.com.