## Builtins

Consts Types Logic Arith Bit/Set String Data Iterator Function IO
`nil` `num` `and` `+` `~` `parse` `len` `iter` `bind` `print`
`_` `str` `or` `-` `|` `repr` `tail` `pairs` `@` `error`
`true` `tbl` `!` `*` `&` `bin` `const` `range`   `import`
`false` `fn_` `==` `/` `&~` `oct` `push` `repeat`
`inf`   `!=` `//` `<<` `hex` `pop` `random`
`E`   `is` `%` `>>` `chr` `++` `map`
`PI`   `<` `^`   `ord` `sub` `filter`
`>` `log`   `find`   `reduce`
`<=` `abs`   `replace`   `any`
`>=` `floor`   `split`   `all`
`ceil`   `join`   `zip`
`cos`   `pad`   `chain`
`acos`   `strip`   `take`
`sin`       `drop`
`asin`       `min`
`tan`       `max`
`atan`       `sort`
`reverse`

## Constants

nil, _, false

Representation of nil, the absence of a value.

true

Arbitrarily 1.

Comparison functions return this value on success, however any non-nil value is considered true.

inf

Numeric representation of infinity.

e

The constant E = 2.718281..

pi

The constant PI = 3.141592..

## Type Casts

num(x) -> num

Converts x to a number.

By default returns `0`.
If x is a number, x is returned unmodified.
If x is a string, x is parsed as a number.

str(x) -> str

Converts x to a string.

By default returns `""`. If x is a string, x is returned unmodified Otherwise, returns repr(x, 0)

tbl(x[, tail]) -> tbl

Converts x to a table.

By default returns `[]`.
If x is a number, the table will be preallocated for x pairs.
If x is a table, a shallow copy of x is returned.
If x is iterabe, x is exhausted and stored in the resulting table as either key/value pairs or at increasing indices.

If a tail is provided, the new table inherits the tail’s elements.

fn_(x) -> fn

Converts x to a function.

By default a function that consumes all arguments is returned. If x is a function, x is returned unmodified.

Note: the the name `fn_` is used to avoid conflict with function declarations.

## Logic Operations

x and y -> bool

Lazily evaluates the logical and of x and y.

y or y -> bool

Lazily evaluates the logical or of x and y.

!x -> bool

Evaluates the logical inverse of x.

x == y -> bool
x != y -> bool

Tests x and y for equality.

If x/y are nil, result is always true.
If x/y are numbers or strings, result is true if x and y are the same value.
If x/y are tables or functions, result is true if x and y reference the same value.

is(x, t) -> bool

Returns true if x is of type t.

If x and t are both tables, returns true if x inherits t.

x < y -> bool
x > y -> bool
x <= y -> bool
x >= y -> bool

Compares x and y.

Numbers are ordered numerically. Strings are ordered lexicographically.

## Arithmetic Operations

+x -> num
x + y -> num

Returns x unmodified or the sum of x and y.

-x -> num x - y -> num

Returns the negation of x or the difference of x and y.

x * y -> num

Returns the product of x and y.

x / y -> num

Returns the quotient of x and y.

x // y -> num

Returns the floored quotient of x and y.

x % y -> num

Returns the modulo of x and y.

x ^ y -> num

Returns x raised to the power of y.

log(x[, base]) -> num

Returns the logarithm of x.

By default the base is e.

abs(x) -> num

Returns the absolute value of x.

floor(x) -> num

Returns the largest integer value <= x.

ceil(x) -> num

Returns the smallest integer value >= x.

cos(x) -> num
acos(x) -> num

Returns the cosine and arc-cosine in radians.

sin(x) -> num
asin(x) -> num

Returns the sine and arc-sine in radians.

tan(x) -> num
atan(y[, x]) -> num

Returns the tangent and arc-tangent in radians.

Optionally, atan can take two values. This is equivalent to `atan(y/x)` but in the correct quadrant.

## Bitwise/Set Operations

~x -> v
x ~ y -> v

Returns the bitwise not of x or the exclusive-or of x and y.

If x and y are tables, `~` performs the symmetric-difference of their keys.

x | y -> v

Returns the bitwise-or of x and y.

If x and y are tables, `|` performs the union of their keys.

x & y -> num

Returns the bitwise-and of x and y.

If x and y are tables, `&` performs the intersection of their keys.

x &~ y -> num

Returns the bitwise and of x and ~y.

If x and y are tables, `&~` performs the set-difference of their keys.

x << y -> num

Returns x bit shifted left arithmetically by y digits.

x >> y -> num

Returns x bit shifted right arithmetically by y digits.

## String Operations

parse(x) -> v

Returns the string x parsed as a Mu literal.

Returns nil if x could not be parsed.

repr(x[, depth]) -> str

Returns a string representation of x.

Depth indicates how many nested tables to represent, by default depth is `1`.

bin(x) -> str
oct(x) -> str
hex(x) -> str

Returns the string representation of x in the specific base.

chr(x) -> str

Returns the character represented by the number x in ascii.

ord(x) -> num

Returns the numeric value of the character x in ascii.

find(x, match) -> lower, upper

Finds the first occurance of match in x.

Otherwise, the lower and upper bounds of match are returned.

replace(x, m, r) -> str

Replaces each occurance of m with r in x.

split(x[, delim]) -> iter

Returns an iterator of the substrings separated by the delimiter.

By default the delimiter is `''`.

join(x[, delim]) -> str

Joins each element of x into a string separated by the delimiter.

By default the delimiter is `''`.

Pads x with padding until x has a length of at least len.

If len is negative, padding is added to the beginning of the string.
By default the padding is `' '`.

Padding is stripped from both sides of x when dir is nil, the beginning when dir is negative, and the end when dir is positive.
By default the padding is `' '`.

## Data Structure Operations

len(x) -> num

Returns the number of elements in x.

tail(x) -> tbl

Returns the tail chain of x.

const(x) -> y

Returns a constant reference to x.

push(x, v[, index])

Pushes v onto table x before the index.

By default, v is push onto the end of the table.

pop(x[, index]) -> v

Pops v off the table x from the index

By default, v is popped off the end of the table.

x ++ y -> v

Returns the concatenation of x and y.

When x/y are tables, a third argument can be provided to specify the offset for y.

sub(x, lower[, upper]) -> v

Returns a subset of x specified by the range [lower, upper).

Negative bounds indicate offsets from the right, and infinity indicates an unlimited boundary.
The default upper bound is lower+1.

## Iterator Operations

iter(x) -> iter

Returns an iterator that iterates over the elements of x.

pairs(x) -> iter

Returns an iterator that iterates over the key/value pairs of x.

If x is not a table, increasing indices are used.

range([start][, stop][, step]) -> iter

Returns an iterator through the range between start and stop incrementing by step.

By default start is `0`, stop is `inf`, and step is `1`.

repeat(x[, n]) -> iter

Returns an iterator that repeats x, n times.

By default n is `inf`.

random([n]) -> iter

Returns a pseudo-random number generator seeded by n.

By default an arbitrary seed is used.
If the same n is passed into random, the same random sequence will be generated.

map(x, iter) -> iter

Lazily applies the x to each element in the iterator.

If x returns nil, the element is filtered out.

filter(x, iter) -> iter

Lazily filters out elements in the iterator when x returns false.

reduce(x, iter[, ..init]) -> iter

Reduces the iterator to a single value by repeatedly applying x to an accumulator and element.

The inits are used to start the accumulator.
If the inits are nil, the first element of iter is used.

any(x, iter) -> bool

Returns true if x returns true for any element in the iterator.

all(x, iter) -> bool

Returns true if x returns true for each element in the iterator.

zip(..iters) -> iter

Iterates over the arguments in parallel, returning the aggregated elements.

If there is only a single iterator, it is treated as an iterator of iterators.

chain(..iters) -> iter

Iterates over the arguments in series.

If there is only a single iterator, it is treated as an iterator of iterators.

take(n, iter) -> iter

Consumes elements from the iterator and iterates over the consumed elements.

If n is a number, n elements are consumed. If n is a function, elements are consumed until n returns true.

drop(n, iter) -> iter

Consumes elements from the iterator and iterates over the remaining elements.

If n is a number, n elements are consumed. If n is a function, elements are consumed until n returns true.

min(..args) -> min

Returns the minimum value based on the comparison operators.

If only one argument is provided, it is iterated over to find the minimum.
The result is ordered by only the first value.

max(..args) -> max

Returns the maximum value based on the comparison operators.

If only one argument is provided, it is iterated over to find the maximum.
The result is ordered by only the first value.

sort(x) -> iter

Returns an iterator that iterates over the elements of x in sorted order.

The result is ordered by only the first value.

reverse(x) -> iter

Iterates over the elements of x in reversed order.

## Function Operations

bind(x, ..args) -> fn

Returns a function that will call x with args prepended to arguments.

a @ b -> fn

Returns a function that calls the functions composed from right to left.

## IO Operations

print(..xs)

Prints each of the arguments and appends a newline.

repr is called on any argument that is not a string.

error(..xs)

Errors with a message composed in the same was as print.

import(name) -> module

Imports a module.

Available modules are implementation dependent.