Maps in Scilab
Maps are Scilab’s built-in associative data type (sometimes called hashes or dicts in other languages).
To create an empty map, use the mlist
function.
Set key/value pairs using typical name(key) = val
syntax.
Printing a map with disp
will show all of its key/value pairs.
Get a value for a key with its index.
If the key doesn’t exist, the zero value (e.g., 0
for integers) of the value type is returned.
The size
function returns the number of key/value pairs when called on a map.
To remove key/value pairs from a map, use appropriate indexing.
To remove all key/value pairs from a map, simply clear the lists.
The second return value when getting a value from a map indicates if the key was present in the map.
You can also declare and initialize a new map in the same line with this syntax.
Note that maps appear in the form [keys:values]
when printed with disp
.