On Wed, Feb 15, 2017 at 11:08 AM, Will Faught <[email protected]> wrote:
> The go/types.Typ decl:
>
> var Typ = []*Basic{
> Invalid: {Invalid, 0, "invalid type"},
>
> Bool: {Bool, IsBoolean, "bool"},
> Int: {Int, IsInteger, "int"},
> Int8: {Int8, IsInteger, "int8"},
> ...
> }
>
> Typ is a slice of pointer to Basic—got it; Basic is a struct—got it; the
> {Bool, IsBoolean, "bool"} stuff is clearly a Basic or *Basic—got it; but
> where is the map syntax coming from? How does that work?
That's not "map syntax", it's general composite literal syntax and is
permitted for all kinds of composite literals. For a slice, it means
that the element with index `Invalid` gets the value `{Invalid, 0,
"invalid type"}`, and so forth. For a slice composite literal the
keys (in this case, `Invalid`, `Bool`, etc.) must all be non-negative
integer constant expressions.
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].
For more options, visit https://groups.google.com/d/optout.