Every value in MathMap is a tagged tuple. This means it consists of one or more numbers (currently stupidly limited to 9) and a symbolic tag. RGBA colors, for example are represented by tuples of length 4 with the tag rgba (for red, green, blue, alpha). The value rgba:[1,0,0,1] for example, represents the fully opaque color red.
Single numbers are represented by tuples of length 1 with the tag nil (which is the default tag). For sake of simplicity, single numbers need not be written in tuple syntax, i.e. 3.1415 is equivalent to nil:[3.1415].
There are several other tuple tags which are used by MathMap:
Tag | Purpose |
nil | Default tag |
rgba | RGBA Color |
hsva | HSVA Color |
ri | Complex number |
xy | Cartesian coordinate |
ra | Polar coordinate |
m2x2 | 2x2 matrix |
m3x3 | 3x3 matrix |
image | Image ID |
In order for the tag system to make sense, operators and functions are overloaded based on the types of their arguments. In order for this to work at compile time, types must be statically determined. This means that any expression must have only one possible type, e.g. the expression if x then abc:[1,2,3] else xyz:[4,5] end is not valid. Furthermore, all assignments to the same variable must have the same type. Hence, v=[1,2];v=[1,2,3] is not valid.
Tuple types are expressed in this manual in the form T:L where T is the tag and L is the length, e.g. rgba:[1,0,0,1] has the type rbga:4.
Elements of tuples can be extracted by the indexing operator []. The expression p[0], for example, extracts the first element of p and is of type nil:1.