3 ms·
> Isn't that pretty common? AFAIK basically just 3 wide-spread languages which do this, and they're all known for their idiosyncratic behaviour: C++, Perl, and
by masklinn 4y ago
> Isn't that pretty common?
AFAIK basically just 3 wide-spread languages which do this, and they're all known for their idiosyncratic behaviour: C++, Perl, and PHP.
A few languages provide this as opt-in via a subtype (Python's defaultdict) or init (Ruby's Hash.new with a block parameter).
Some more will do it via an opt-in callsite API e.g. Python's `setdefault`, Java's `computeIfAbsent`, Rust's `entry` API.
- kragen 4y agoperl only does this in some cases; unlike with std::map, this is safe: my $x = $h{$v}; this is not safe because it autovivifies $h{$v} as an ARRAY ref: my $x = $h{$v}[$i]; with respect to idiosyncratic behavior, if a language doesn't have idiosyncratic behavior, it has no reason to exist; it's just gratuitously incompatible syntax for already-available semantics