cary = Associative Array();
cary = [=> ];
[=> ]
cary = Associative Array();
cary["state"] = "NC";
cary["population"] = 116234;
cary["weather"] = "cloudy";
cary["population"] += 10;
cary["weather"] = "sunny";
cary["high schools"] = {"Cary", "Green Hope", "Panther Creek"};
cary = Associative Array();
cary << Set Default Value( "Cary, NC" );
To determine whether there is a default value set for an associative array, use the <<Get Default Value message.
cary << Get Default Value;
"Cary, NC"
If there is no default value, Empty() is returned.
Besides the Set Default Value message, a default value can be set in the literal constructor using =>value without a key.
counts = ["a" => 10,
"b" => 3,
=> 0]; // default value of 0
counts["c"] += 1;
Show( counts );
counts = ["a" => 10, "b" => 3, "c" => 1, => 0];
In the first line, the default value is set to 0. In the second line, the key "c" does not exist in counts. In the output, the key "c" is created with the default value of 0 and then incremented by 1.
map = [=>];
map = Associative Array();
map = [=>0];
map = Associative Array( 0 );
map = ["yes" => 0, "no" => 1];
map = ["yes" => 0, "no" => 1, => 2];
map = Associative Array( {{"yes", 0}, {"no", 1}} );
map = Associative Array( {{"yes", 0}, {"no", 1}}, 2 );
map = Associative Array( {"yes", "no"}, {0, 1} );
map = Associative Array( {"yes", "no"}, {0, 1}, 2 );
map = Associative Array( :name, :height );
map = Associative Array(:name, :height, .);
set = Associative Array( {"yes", "no"} );
set = Associative Array( :name );