Associative array mutation of a value

Tobias Pankrath tobias at pankrath.net
Thu Feb 6 07:03:44 PST 2014


On Thursday, 6 February 2014 at 14:15:47 UTC, bearophile wrote:
> 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


AA[key] = val; ?



More information about the Digitalmars-d mailing list