Go, like Python, doesn't have such a distinction, thingvalue could be an array item, a map (dict, or hash) access, or access to a char in a string. In those languages, it's the operand that defines which operation to use

Again, no.

Go is a strongly typed language, every variable has a well-defined type associated it. You can have a nested map type c := map[string]map[string]int, in which case you (and the compiler) can know that its element c["key"] is of type map[string]int and the sub-elements of that (c["key"]["subkey"]) are of type int. Assigning a value of any other type to those keys would result in a compile time error.

So in theory, you could have autovivification in the language - but in practice you can't, you have to explicitly initialize the mid-level maps yourself, as explained by this blog post: Go maps in action.

The underlying reason for this, I think, is that Go differentiates between a nil map and an empty map. The zero value of a(n uninitialized) map is a nil map, you have to initialize yourself with make. A nil map can be safely read from, but assigning any key to it results in a runtime panic. When you declare a nested map as the example above, the mid-level maps will be nil maps, and as such, are not safe to assign to. (I consider this to be a design wart of the language.)


In reply to Re^2: Does Go steal from Perl? :-) by kikuchiyo
in thread Does Go steal from Perl? :-) by reisinge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.