Maps
11 entries. What each one takes, what it returns, and a working example.
Removes all keys.
Does not return a value; removes all pairs from the map (the map is emptied in place).
Note
The same map object is kept, only its contents are cleared; other variables holding it see it empty too.
m = mapNew() mapPut(m, "a", 1) mapClear(m) plot(mapSize(m))
One pair is written then the map is cleared; the size 0 is plotted.
Whether the key exists (true/false).
true if the key exists in the map, otherwise false.
Note
A value being na is different from the key being absent; this function only checks whether the key exists.
m = mapNew() mapPut(m, "a", 1) plot(iff(mapContains(m, "a"), 1, 0))
Since key "a" was written, it plots 1.
Shallow copy of the map.
A new, independent map holding the same pairs.
Note
The copy is independent — writing to the copy does not affect the original. Useful for branching a new state.
a = mapNew() mapPut(a, "x", 1) b = mapCopy(a) mapPut(b, "y", 2) plot(mapSize(a))
A new pair is added to the copy, but the original still holds one pair so its size 1 is plotted.
Value for the key (na if absent).
The value at the key, or na if the key is absent (or the input is not a map).
Note
A missing key does not raise an error, it returns na — conditions run safely over na.
m = mapNew() mapPut(m, "high", highest(high, 20)) plot(mapGet(m, "high"))
Stores the 20-bar highest level under the "tepe" key and reads it back to plot it.
Returns the keys as an array. Result: Arr(len=0, [])
An array holding the map's keys in insertion order.
Note
You can read the array's length with arraySize and walk its elements with the array functions.
m = mapNew() mapPut(m, "a", 1) mapPut(m, "b", 2) plot(arraySize(mapKeys(m)))
Two keys are written; the length of the key array, 2, is plotted.
Creates an empty table that maps a key to a value. When you want to reach things by name rather than by position it suits better than an array — keeping a number per symbol name, for instance.
An empty map (key→value). Keys may be text, number or boolean.
Note
A map holds key→value pairs; writing the same key again overwrites the old value. Values may be numbers, text, booleans or series.
When to use
When you want to store a value against a label (a symbol, a level name, a state) and read it back by name later; when you need access by a meaningful key rather than a numeric index.
m = mapNew() mapPut(m, "threshold", 42) plot(iff(mapContains(m, "threshold"), close, open))
Creates an empty map, writes 42 under the "esik" key; since the key exists it plots close.
Writes a value for a key in the map; if the key already exists it overwrites and returns the old value. Otherwise it creates a new entry.
The value previously held at the key, or na if the key was absent. The map is changed in place.
Note
If the key already exists its value is updated and the old value is returned; otherwise a new pair is added and na is returned.
m = mapNew() previous = mapPut(m, "k", 10) mapPut(m, "k", 20) plot(mapGet(m, "k"))
Writes 10 then 20 under key "k"; the previous value is na on the first write. The final value 20 is plotted.
Copies harita2 into harita1.
Does not return a value; copies all pairs from map2 into map1 (colliding keys are overwritten).
Note
Only the target (map1) changes; the source (map2) is left unchanged.
a = mapNew() mapPut(a, "x", 1) b = mapNew() mapPut(b, "y", 2) mapPutAll(a, b) plot(mapSize(a))
b's pair is added to a; a now holds two pairs so the size 2 is plotted.
Removes the key and returns its value.
The value of the removed key, or na if the key was absent. The map is changed in place.
Note
If the key is absent it silently returns na with no error.
m = mapNew() mapPut(m, "a", 5) mapRemove(m, "a") plot(iff(mapContains(m, "a"), 1, 0))
Key "a" is written then removed; since it is no longer present it plots 0.
Number of keys.
The number of key-value pairs in the map; 0 if the input is not a map.
Note
Returns 0 for an empty map. Writing the same key again does not increase the size.
m = mapNew() mapPut(m, "a", 1) mapPut(m, "b", 2) plot(mapSize(m))
Two distinct keys are written; the size 2 is plotted.
Returns the values as an array. Result: Arr(len=0, [])
An array holding the map's values in key insertion order.
Note
For numeric values you can combine values with array functions such as arraySum / arrayAvg.
m = mapNew() mapPut(m, "a", 10) mapPut(m, "b", 20) plot(arraySum(mapValues(m)))
Values are 10 and 20; the sum of the value array, 30, is plotted.