Associative array mutation of a value

bearophile bearophileHUGS at lycos.com
Thu Feb 6 06:15:46 PST 2014


Recently Erlang language has added several things:
http://joearms.github.io/2014/02/01/big-changes-to-erlang.html

One interesting change is the syntax to handle associative arrays 
(that are meant to be used a little like records):

> Updating a map is done as follows:
> 
> NewX = X#{ key1 => Val1, ... KeyN := ValN, ...}

X is the old associative array. "=>" adds a mew key, while ":=" 
updates an already existing key, and if it's not present an error 
is generated. So a spelling mistake cannot accidentally introduce 
a new key if you want to update some value. This avoids a common 
mistake.

I am not suggesting to add a new syntax to D, but perhaps a 
simple "AA.update(key, val)" function in the object module can be 
useful.

Bye,
bearophile


More information about the Digitalmars-d mailing list