Loading

PUT

maps

The PUT function inserts a new key-value pair in a map. If the key already exists in the input MAP, the value is replaced by the new one.

PUT function puts the reference of the MAP on top of the stack.

PUT is available since version 1.0.0.

See also

Signatures

Examples

{ 'foo' 42 'bar' true } 'newValue' 'newKey' PUT 3.1415 'bar' PUT
{ 'audi' 150 'volvo' 120 'dacia' 310 } 'brandcount' STORE //vehicle count per brand [ 'dacia' 'audi' 'dacia' 'dacia' 'porsche' 'volvo' 'tesla' ] //new inputs <% //enter the foreach loop, next list value is put on the top of the stack 'brand' STORE //store the brand $brandcount $brand GET //search for existing key. see also CONTAINSKEY DUP ISNULL //this test will consume the top of the stack. hence the DUP before. <% DROP $brandcount 1 $brand PUT %> //key do not exist, create it with value=1 <% $brandcount SWAP 1 + $brand PUT %> //key exists, increment the brand count IFTE DROP // PUT returns the updated list on the stack. try to comment this line... // ... you can see that the stack references to the brandcount map. %> FOREACH $brandcount //display the updated brand list