Function's library
Logic and arithmetic
The basic arithmetic operators are: +, -, *, / (plus, minus, times, divide)
(+ 3 5)
Returns the sum of 3 and 5, 8. These operators are n-ary, thus more than two arguments can be employed.
(- 1 2 3 4 5 6 7)
Returns 1 - 2 - 3 - 4 - 5 - 6 - 7 = -26.
Arithmetic operators
Function name | Synopsis | Description | Example |
---|---|---|---|
+ | (+ <exp> <exp>+) | Sum | (+ 6 4) ⇒ 10 |
- | (- <exp> <exp>+) | Subtraction | (- 6 4) ⇒ 2 |
* | (* <exp> <exp>+) | Multiplication | (* 6 4) ⇒ 24 |
/ | (/ <exp> <exp>+) | Division | (/ 6 3) ⇒ 2 |
% | (% <exp> <exp>) | Modulo | (% 6 4) ⇒ 2 |
log10 | (log10 <exp>) | Base 10 logarithm | (log10 124) |
ln | (ln <exp>) | Natural logarithm | (ln 51.6) |
pow | (pow <exp> <exp> | Exponential | (pow 5 2) ⇒ 25 |
sqrt | (sqrt <exp>) | Square root | (sqrt 9) ⇒ 3 |
sin | (sin <exp>) | Sine | (sin 1.456) |
cos | (cos <exp>) | Cosine | (cos 1.456) |
tan | (tan <exp>) | Tangent | (tan 1.456) |
atan | (atan <exp>) | Inverse tangent | (atan 1.456) |
atan2 | (atan2 <exp> <exp>) | Four-quadrant inverse tangent | (atan2 1.456 2.6554) |
fmod | (fmod <exp> <exp>) | Floating point modulo | (fmod 1.456 5) |
abs | (abs <exp>) | Absolute value | (abs -1) |
floor | (floor <exp>) | Round value down | (floor 5.3) ⇒ 5 |
ceil | (ceil <exp>) | Round value up | (ceil 7.9) ⇒ 8 |
Logic operators
Function name | Synopsis | Description | Example |
---|---|---|---|
and | (and <exp>+) | Logic and (short circuit) | (and 1 4 7 nil) ⇒ nil |
or | (or <exp>+) | Logic or (short circuit) | (and 6 4 7 nil) ⇒ 1 |
not | (not <exp>) | Logic not | (not 5) ⇒ nil |
xor | (xor <exp>) | Logic xor | (xor 6 2) |
Arithmetic comparison operators
Function name | Synopsis | Description | Example |
---|---|---|---|
< | (< <exp> <exp>) | Less than | (< 6 2) ⇒ nil |
⇐ | (⇐ <exp> <exp>) | Less than or equal | (⇐ 2 2) ⇒ 1 |
> | (> <exp> <exp>) | Greater than | (> 6 2) ⇒ 1 |
>= | (>= <exp> <exp>) | Greater than or equal | (>= 3 3) ⇒ 1 |
Number conversion
Function name | Synopsis | Description | Example |
---|---|---|---|
int | (int <exp>) | Returns the integer value of <exp> | (int 5.3) |
long | (long <exp>) | Returns the long value of <exp> | (long 234) |
float | (float <exp>) | Returns the float value of <exp> | (float 234) |
double | (double <exp>) | Returns the double value of <exp> | (double 234) |
string | (string <exp>) | Returns the string representation of <exp> | (string 234) |
Generic comparison operators
Function name | Synopsis | Description | Example |
---|---|---|---|
= | (= <exp> <exp>) | Comparison of two values | (= 5 5) ⇒ 1 |
List operators
These functions operate in place: the list passed as argument is modified! Indexes in a list start at 0.
Function name | Synopsis | Description | Example |
---|---|---|---|
size | (size <exp>) | Length of a list | (size [1, 2, 3]) ⇒ 3 |
empty | (empty <exp>) | Returns non nil if the list is empty | (empty [1, 2, 3]) ⇒ nil |
at | (at <exp> <exp>) | Returns an element at a given position in a list | (at [1, 2, 3] 1) ⇒ 2 |
front | (front <exp>) | Returns the first element in a list | (front [1, 2, 3]) ⇒ 1 |
back | (back <exp>) | Returns the last element in a list | (back [1, 2, 3]) ⇒ 3 |
push | (push <exp> <exp>) | Adds an element at the end of a list | (push [1, 2, 3] 4) ⇒ [1, 2, 3, 4] |
pop | (pop <exp>) | Removes the last element of a list and returns it | (pop [1, 2, 3]) ⇒ 3 |
insert | (insert <exp> <exp> <exp>) | Adds an element at a given position in a list | (insert [1, 2, 3] 0 “A”) ⇒ [“A”, 1, 2, 3] |
erase | (erase <exp> <exp>) | Removes the element at the given position in a list | (erase [1, 2, 3] 0) ⇒ [2, 3] |
remove | (remove <exp> <exp>) | Removes the element equal to the given one in a list | (remove [“A”, “B”] “A”) ⇒ [“B”] |
clear | (clear <exp>) | Removes all elements from a list | (clear [“A”, “B”]) ⇒ [] |
choose | (choose <exp>) | Returns a random uniform element from a list | (choose [“A”, “B”]) ⇒ “A” |
contains | (contains <exp> <exp>) | Returns non nil if an element is contained in the list | (contains [“A”, “B”] “B”) ⇒ 1 |
car | (car <exp>) | Returns the first element in the list | (car [“A”, “B”, “C”]) ⇒ “A” |
cdr | (cdr <exp>) | Returns all but the first element in the list | (cdr [“A”, “B”, “C”]) ⇒ [“B”, “C”] |
Map operators
These functions operate in place: the map passed as argument is modified!
Function name | Synopsis | Description | Example |
---|---|---|---|
size | (size <exp>) | Number of keys in the map | (size {“A” : 1, “B” : 3}) ⇒ 2 |
empty | (empty <exp>) | Returns non nil if the map is empty | (empty {}) ⇒ 1 |
containsKey | (containsKey <exp> <exp>) | Returns non nil if the key is in the map | (containsKey {“A” : 1, “B” : 3} “C”) ⇒ nil |
containsValue | (containsValue <exp> <exp>) | Returns non nil if the value is in the map | (containsKey {“A” : 1, “B” : 3} 3) ⇒ 1 |
get | (get <exp> <exp>) | Returns the value associated with the key (if present, nil otherwise) | (get {“A” : 1, “B” : 3} “A”) ⇒ 1 |
put | (put <exp> <exp> <exp>) | Adds a new association to the map | (put {“A” : 1, “B” : 3} “C” 6) ⇒ {“A” : 1, “B” : 3, “C” : 6} |
keys | (keys <exp>) | Returns a list of the keys in the map | (keys {“A” : 1, “B” : 3}) ⇒ [“A”, “B”] |
values | (values <exp>) | Returns a list of the values in the map | (values {“A” : 1, “B” : 3}) ⇒ [1, 3] |
Generic
Function name | Synopsis | Description | Example |
---|---|---|---|
clone | (clone <exp>) | Returns a copy of the passed value | (clone “Hello”) ⇒ “Hello” |
random | (random) | Returns a random number between 0 and (randmax) | (random) ⇒ 543 |
randmax | (randmax) | Returns the maximum random number value returned by (random) | (randmax) |
debug | (debug <exp>) | Prints <exp> on the screen. To pass multiple values create a list | (debug “Test”) |
concat | (concat <exp>) | Concatenates the elements in a list into a single string | (concat [1, 2, “Test”]) ⇒ “12Test” |
Migration and fork
Function name | Synopsis | Description | Example |
---|---|---|---|
migrate | (migrate <exp>) | Migrates to the given node | (migrate (getSuccessor)) |
fork | (fork <exp>) | Forks to the given node: if the return value is nil, the execution is in the copy of the ant that has not migrated, else it is the copy of the ant that migrated to the target. | (fork (getSuccessor)) |