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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |