I would guess that in the case of AST nodes, you're likely more interested in the *identity* of the nodes than their *values*. In that case, you should use the pointers to the nodes as your map keys.
If the *values* truly are what you care about, use the go/format package to convert the node back to source code, and use the resulting string as your map key. On Thursday, March 16, 2023 at 3:24:49 PM UTC-7 alex-coder wrote: > >> Sure, convert to a string and use that as a map key. > :-) no, no, no. it looks very very ugly. > > четверг, 16 марта 2023 г. в 00:26:35 UTC+3, Ian Lance Taylor: > >> On Wed, Mar 15, 2023 at 2:16 PM alex-coder <a.gus...@gmail.com> wrote: >> > >> > Ian, thank you. >> > but may be the is any workaround ? >> > Use as a key not directly but like a derived from those >> interface/structure types ? >> > Of course I may declare key like string and use switch + .(type) to >> mimic it. >> >> Sure, convert to a string and use that as a map key. >> >> By the way, I should say that although you can't use `ast.Field` as a >> map key type, you can use `*ast.Field`. Of course then two different >> Field values that happen to look exactly the same will get different >> map entries. So it kind of depends on what you want to do. >> >> 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/c08ef64c-a068-4a25-afd6-46cb64ce4f55n%40googlegroups.com.