GET


lists maps binary
Since v1.0.0
Available on all platforms
See also

Retreive a value in a MAP or a list.

The GET function consumes on the top of the stack a list (or a map) and the index (or the key), then put the result on the stack.

If key is not found, it returns NULL on the stack.

If index is out of bound, GET raises an error.

Since 2.1, the index can be negative. In this case the effective index is index + size of the LIST or BYTE ARRAY.

Signature

Examples

// Get a value in a map from the key { 'foo' 42 'bar' true } 'foo' GET // Get a value in a list from the index [ 3 12 15 ] 0 GET // Try to get a value from a non existing key (result will be NULL) { 'foo' 42 'bar' true } 33 GET
{ '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