All languages are built using concepts from others, perl is no exception (is takes a lot from C, shell languages, awk...), so even if there was autovivification in Go, there wouldn't be much to say about it.

But this is not autovivification for two reasons. First, autovivification is about nested structure. When you try to use a non existing element of a structure (array or hash) as a structure itself, perl may create that element for you. For example, if %hash is empty and you try to modify $hash{Clef}[0], you are trying to access the array at key Clef, so perl will create an array. In your Go example, it just shows that a non existing int value in a map is treated as 0.

The second reason this is not autovivification, is because it is impossible to have autovivification (AFAICT) in this language. You'll notice that in perl, you know that $hash{Key} is an hash value because of { }. And you know that it contains an array because [0] acccesses an array element. Go, like Python, doesn't have such a distinction, thing[value] 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, while in perl it's the operator that defines what the operand is. This means that in python* if you try to access thing[value][otherValue] and the first level doesn't exist, python has no idea if you were trying to access a string, an array, a dict or something else, so it can't create it for you.

*I know python better than Go, but the idea still applies


In reply to Re: Does Go steal from Perl? :-) by Eily
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.