Lists and dictionaries (
Several values held as one: a list, values in order, or a dictionary, values looked up by key.
Syntax
{a,b,c}
{}
{key:value,key:value,…}
{:}
list[index]
dictionary[key]
CONCAT(a,b,…)
SUBRANGE(list,first,count)
INDEXOF(list,value,from)
CONTAINS(list,value)
| Part | Meaning |
|---|---|
| a, b, c | The list's items: any expressions, even lists and dictionaries. |
{} |
An empty list. |
| key:value | A dictionary's entries: each key and its value. |
{:} |
An empty dictionary. |
| index | Which item of a list: a whole number, from 0 (the first item is [0]). |
| key | Which value of a dictionary. |
CONCAT |
Lists joined into one (a value that isn't a list is added as an item); dictionaries merged; strings joined. |
SUBRANGE |
count items of a list, from first (from 0); with no count, to the end. Of a string, its characters. |
INDEXOF |
Where value first is in a list (from 0, looking from from if given), or -1 if it isn't; in a string, where a string first is. |
CONTAINS |
Whether value is an item of a list, a key of a dictionary, or a string in a string. |
Result
A list or a dictionary; with [ ] after it, one of its values.
Examples
In the example drawing:
| Expression | Gives |
|---|---|
{10,20,40}[0] |
10 |
{10,20,40}[2] |
40 |
{10,20,40}.COUNT |
3 |
{10,20}+{40} |
{10,20,40} |
{"A4":210,"A3":297}["A3"] |
297 |
{"A4":210,"A3":297}.KEYS |
{"A4","A3"} |
{"A4":210,"A3":297}.VALUES |
{210,297} |
{1:"one",2:"two"}[L/250] |
"two" |
{P1,P2}[1] |
[500,300] |
{10,20,40}.LAST |
40 |
CONCAT({10,20},{40},50) |
{10,20,40,50} |
SUBRANGE({10,20,40,50},1,2) |
{20,40} |
SUBRANGE({10,20,40,50},2) |
{40,50} |
INDEXOF({10,20,40},40) |
2 |
INDEXOF({10,20,40},30) |
-1 |
CONTAINS({"A4":210,"A3":297},"A5") |
FALSE |
CONCAT("Box ",L,"x",W) |
"Box 500x300" |
SUBRANGE("Lid flap",4) |
"flap" |
INDEXOF("Lid flap","flap") |
4 |
Notes
Keep a list or dictionary in a variable and use it by name: SIZES={"A4":210,"A3":297}, then SIZES["A4"].
- Keys are numbers, strings, positions or TRUE and FALSE. A number key matches the same number however it is
written (
2,2.0,4/2); strings match exactly. A key given twice counts the first time. - Properties:
.COUNTis how many items or entries there are; a list's.FIRSTand.LASTare its first and last items; a dictionary's.KEYSand.VALUESare lists of its keys and its values, in order. - Joining:
+joins two lists, and two dictionaries (the second's values in place of the first's for the keys they share). - Comparing:
==compares item by item. - An index that isn't a whole number from 0 to
.COUNT-1, or a key that isn't there, is an error. To give a value for those instead, use SWITCH. - Lists and dictionaries are values: they don't change. In a block, build one up with
LIST = LIST + {X}. FOREACH runs a block for each item of a list, or each key of a dictionary. [x,y](square brackets) is a position, not a list.