Autovivification in Perl happens when you try to dereference an undefined value as an arrayref or hashref. A new array or hash is silently created and the undefined value is changed to be a reference to that array or hash.
There's no autovivification going on in the example you gave. There's only one hash used (though Go calls them maps, not hashes), and it's explicitly declared in the first line of the function.
The counts[input.Text()]++ part relies on:
Go doesn't require you to predeclare what keys you'll use in a map. (Pretty common. Most languages that provide a hash/dictionary/map-like structure don't require you to predeclare what keys you'll use.)
If you read a map using a key which hasn't been assigned to yet, you get null/undefined. (Again very common.)
The language treats undefined values as zero when used in numeric contexts such as with the increment operator. (Almost universal in weakly typed languages.)
In reply to Re: Does Go steal from Perl? :-)
by tobyink
in thread Does Go steal from Perl? :-)
by reisinge
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |