Skip to content

Standard Libraries

Christopher Hittner edited this page Feb 13, 2019 · 2 revisions

Lomda offers a variety of rudimentary libraries that provide basic operations. Furthermore, there are several mathematical functions that can be accessed without importing any libraries.

Default Functions

These functions do not require imports to be accessed, and thus are very similar to macros.

Name Type Description
acos(x) R -> R Computes the arccosine of a number.
acosh(x) R -> R Computes the hyperbolic arccosine of a number.
asin(x) R -> R Computes the arcsine of a number.
asinh(x) R -> R Computes the hyperbolic arcsine of a number.
atan(x) R -> R Computes the arctangent of a number.
atanh(x) R -> R Computes the hyperbolic arctangent of a number.
cos(x) R -> R Computes the cosine of a number.
cosh(x) R -> R Computes the hyperbolic cosine of a number.
exp(x) t -> t*t+t Computes e to the power of a value.
log(x) t -> t*t+t Computes the log of a value.
max(x) [R] -> R Determines the largest value in a list.
min(x) [R] -> R Determines the smalest value in a list.
sin(x) R -> R Computes the sine of a number.
sinh(x) R -> R Computes the hyperbolic sine of a number.
sqrt(x) t -> t*t+t Computes the square root of a number.
tan(x) R -> R Computes the tangent of a number.
tanh(x) R -> R Computes the hyperbolictangent of a number.

Standard Libraries

The standard libraries provide various functions and constants that are useful for writing programs.

fs

Libraries for reading and writing to files.

Name Type Description
close(fd) Z -> void Closes a file.
open(path, flags) Z -> Z -> Z Opens a file.
read(fd, n) Z -> Z -> S Reads n bytes from file descriptor fd.
APPEND Z Append to a file.
RDONLY Z Read-only flag.
RDWR Z Read + write flag.
WRONLY Z Write-only flag.

linalg

Functions for performing linear algebraic operations.

Name Type Description
characteristic_polynomial(x) [[R]] -> (R -> R) Generates the characteristic polynomial of a matrix.
det(x) [[R]] -> R Computes the determinant of a matrix using Gaussian reduction.
eig(x) [[R]] -> [R] Computes the eigenvalues of a matrix using the Newton-Raphson method.
gaussian(x) [[R]] -> [[R]] Performs a Gaussian reduction on a matrix.
qr(x) [[R]] -> [[[R]]] Computes a QR decomposition of the matrix.
trace(x) [[R]] -> R Computes the trace of a matrix.
transpose(x) [[R]] -> [[R]] Computes the transpose of a matrix.

math

Miscellaneous math functions.

Name Type Description
isfinite(x) R -> B Determines whether or not a value is finite.
isinfinite(x) R -> B Determines whether or not a value is infinite.
isnan(x) R -> R Determines whether or not a value is not a number.

random

Pseudo-random number generators.

Name Type Description
uniform(a, b) R -> R -> R Generates a number of uniform distribution; x ~ U(a, b)
normal(a, b) R -> R -> R Generates a number of normal distribution; x ~ N(a, b)

sort

Functions for sorting numbers.

Name Type Description
is_sorted(L) [R] -> B Decides whether or not a list is sorted.
mergesort(L) [R] -> void Sorts a list in place using mergesort.
quicksort(L) [R] -> void Sorts a list in place using quicksort.

string

Utilities for interacting with strings.

Name Type Description
strcat(a, b) S -> S -> S Concatenates two strings.
substring(str, i, j) S -> Z -> Z -> S Generates a substring of the given string; str[i:i+j]
strstr(a, b) S -> Z -> Z Computes the index of a string in the first string.

sys

System variables and utilities.

Name Type Description
argv [S] The arguments given to Lomda on the command line.
exit(x) Z -> void Exits the program with a given return code.
stderr Z The file descriptor of stderr.
stdin Z The file descriptor of stdin.
stdout Z The file descriptor of stdout.

Clone this wiki locally