Standard Library
Reference for builtin functions.
This page shows the most used functions with examples. The Function Reference lists every function, macro and package of the ELPS release this site runs, generated from elps itself.
Common Functions
debug-print
Prints the supplied value(s).
json:dump-string
JSON encodes a value, returning the JSON as a string.
json:dump-bytes
JSON encodes a value, returning the JSON as bytes.
to-string
Converts primitive values to their string representation.
to-bytes
Converts a string value to bytes.
to-int
Converts string digits ([0-9]+) and floats to integers. For floats the fractional part is discarded. Allows integer to pass through.
to-float
Converts strings and integers to floats. Allows floats to pass through.
car
Returns the first element in a list.
cdr
Returns the list after the first item.
rest
Returns the sequence (list, vector) after the first item.
first / second
nth
Gets the nth element of a sequence.
map
Applies a function to a sequence of values.
foldl
Reduces a sequence using an applicator function and with an accumulator, evaluating from the left.
foldr
Reduces a sequence using an applicator function and with an accumulator, evaluating from the right.
compose
Returns a function that is the combination of two functions, with the first function using the product of the second function as its input.
unpack
Unpack is a special case of apply and is more cumbersome. Instead of using unpack it is better to use apply and funcall.
flip
Returns a function with the parameter order reversed, the input function must have two parameters.
assoc
Associates a new key and value to a map, returning a copy without mutating the source map.
assoc!
Associates a new key and value to a map, mutating the source map in-place.
dissoc
Dissociate a value from a map via a key, returning a copy without mutating the source map.
dissoc!
Dissociate a value from a map via a key, mutating the source map in-place.
get
Gets a map value by key.
keys
Returns the key values of a map.
key?
Checks if the a key exists in a map.
concat
Concatenates values.
insert-index
Inserts a value into a sequence at a specific index.
stable-sort
Performs a stable sort on a list using a predicate. The last argument can optionally be a function that takes the key and returns the comparison value. Mutates the list in-place.
insert-sorted
Inserts a value in its sort position.
search-sorted
Search uses binary search to find and return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true.
select
Selects values matching the predicate.
reject
Rejects values matching the predicate.
zip
Zips one or more lists, composing a list of values from each input list. Tuples length is restricted to the smallest input list length.
make-sequence
Generates a sequence, with an optional step value.
format-string
Creates a string using format placeholders and values.
reverse
Reverses a sequence.
slice
Returns the sub-slice of a sequence.
list
Returns a list compose of the supplied parameters.
vector
Creates a vector (array) value.
append
Appends to the vector, returning a copy without mutating the source vector.
append!
Appends to the vector, mutating the source vector in-place.
append-bytes
Appends to the byte vector, returning a copy without mutating the source vector.
append-bytes!
Appends to the byte vector, mutating the source vector in-place.
aref
Gets the array element at the given index (counted from zero).
all?
Test all items in a sequence match against a function.
any?
Test if any item in a sequence matches against a function.
true?
Checks if a value is truthy.
Type Checking
empty?
Determine if a sequence or string is empty.
math
The math package has number functions and constants. Write each name with the math: prefix.
| Name | Returns |
|---|---|
(math:abs n) |
The absolute value of n |
(math:floor n), (math:ceil n) |
n rounded down, or up, to an int |
(math:sqrt n) |
The square root of n |
(math:exp n), (math:ln n) |
e to the power n, and the natural logarithm of n |
(math:log base n) |
The logarithm of n to base |
(math:sin r), (math:cos r), (math:tan r) |
Trigonometric functions of r radians. asin, acos, atan and the hyperbolic forms sinh, cosh, tanh, asinh, acosh, atanh are also available |
(math:nan? n) |
true when n is not a number (NaN) |
math:pi, math:inf, math:-inf |
The constants pi, positive infinity and negative infinity |
These functions use floating-point numbers. Do not use them for money: use the decimal functions.
regexp
The regexp package matches text against regular expressions. The pattern syntax is the Go RE2 syntax.
| Name | Returns |
|---|---|
(regexp:regexp-compile pattern) |
A compiled regular expression. A bad pattern raises an error |
(regexp:regexp-match? re text) |
true when text contains a match for re |
(regexp:regexp-pattern re) |
The pattern string of re |
(regexp:regexp? value) |
true when value is a compiled regular expression |
Compile a pattern one time, at the top level of a file, and use it many times. To check a field of a request, you can also use the s:regexp constraint.
regexp-match? finds a match anywhere in the text. Use ^ and $ to match the whole text.
base64
The base64 package encodes bytes as base64 text and decodes it. Both functions return bytes. Use to-string to get a string.
| Name | Returns |
|---|---|
(base64:encode data) |
The base64 encoding of data (a string or bytes), as bytes |
(base64:decode text) |
The bytes that text encodes. Text that is not base64 raises an error |