Skip to content

Standard Library

General functions

print

value:Any -> Any

Prints a value.

assert

condition:Bool -> Bool

Asserts the condition.

error

message:Str? -> Null

Throws a runtime error.

size

value:Any -> Int?

Returns the size of a collection or a string.

clone

value:Any -> Any

Makes a (deep) clone of a value.

exit

_:Null -> Null

Exits the program.

Arrays

list

iterator:(Any -> Any) -> [Any]

Collects the elements generated by an iterator into an array.

slice

array:[Any] -> s:Int -> e:Int -> [Any]

Slices an array between two indexes.

push

array:[Any] -> value:Any -> [Any]

Adds a value to the end of an array.

pop

array:[Any] -> Any

Pops the last value from the array.

shift

array:[Any] -> value:Any -> [Any]

Inserts a value at the front of an array.

unshift

array:[Any] -> Any

Pops the first value from the array.

Objects

delete

obj:{} -> prop:Str -> {}

Deletes a property from an object.

keys

obj:{} -> (Null -> Str?)

Returns an iterator over an object's keys.

values

obj:{} -> (Null -> Any?)

Returns an iterator over an object's values.

exists

obj:{} -> key:Str -> Bool

Checks whether a key exists.

get

obj:{} -> key:Str -> Any

Returns a property.

set

obj:{} -> key:Str -> value:Any -> Any

Set a property to a given value.

dir

obj:{} -> [Str]

Returns a list of keys for a given object.

dirFun

obj:{} -> [Str]

Return the methods of an object.

Iterators

iter

value:Any -> Any

Creates an iterator function from the value.

natural0

_:Null -> (Null -> Int?)

The positive integers.

natural

_:Null -> (Null -> Int?)

The natural numbers.

range

start:Int -> stop:Int? -> (Null -> Int?)

Returns an iterator for the integers from a given starting number until an ending number.

reduce

f:(Any -> Any -> Any) -> iterator:(Null -> Any) -> Any

Reduces an iterator using a binary function.

Example: calculate the sum from 1 to 100.

let sum = fun(n, m) do n+m end
reduce(sum, range(1, 101))

filter

cond:(Any -> Bool) -> iterator:(Null -> Any) -> (Null -> Any)

Filters an iterator using a condition.

map

f:(Any -> Any) -> iterator:(Null -> Any) -> (Null -> Any)

Applies a function to an iterator.

Mathematical functions

PI

3.14159265359

The number pi (π).

E

2.7182818284

Euler's number

sin

value:Num -> Num

Sine function

cos

value:Num -> Num

Cosine function

tan

value:Num -> Num

Tangent function

sqrt

value:Num -> Num

Square-root function

log

value:Num -> Num?

Logarithm function

exp

value:Num -> Num?

Exponential function

pow

base:Num -> exp:Num -> Num

Power function

random

_:Null -> Num

Returns a uniform random variate in [0, 1).

String functions

substr

string:Str -> s:Int -> e:Int -> Str

Substring function

toLower

string:Str -> Str

Converts a string to lowercase.

toUpper

string:Str -> Str

Converts a string to uppercase.

strip

string:Str -> Str

Removes leading and trailing whitespace.

lstrip

string:Str -> Str

Removes leading whitespace.

rstrip

string:Str -> Str

Removes trailing whitespace.

split

string:Str -> separator:Str -> [Str]

Splits a string into a list of string using a separator.

join

strings:[Str] -> separator:Str -> Str

Joins strings into a single string using a separator.

match

pattern:Str -> string:Str -> [Str]

Searches for a regex pattern within a string and returns a list of matches.

replace

pattern:Str -> replace:Str -> string:Str -> Str

Substitutes a regex pattern with a replacement within a string.

Module importing

codeImport

code:Str -> name:Str -> {}

Imports code as a module.

import

filename:Str -> {}

Imports a file at a given path as a module.

netImport

url:Str -> {}

Import a remote module.

Networking

www

url:Str -> Str?

Retrieve a web page.

http

params:HTTPParams? -> method:Str? -> url:Str -> {}

Makes an HTTP request. The parameter HTTPParams is an object defined as

type {
    mode: Str?,
    cache: Str?,
    credentials: Str?,
    headers: {}?,
    redirect: Str?,
    referrerPolicy: Str?,
    body: {}
}
where mode is an HTTP verb (header, get, post, update, or delete), cache...

Time

tsNow

_:Null -> Int

Returns the current timestamp in milliseconds.

dateNow

_:Null -> {}

Returns a the current date.

Casting & type checking

str

value:Any -> Str

Converts a value into a string.

bool

value:Any -> Bool?

Converts a value into a boolean.

int

value:Any -> Int?

Converts a value into an integer.

num

value:Any -> Num?

Converts a value into a string.

typeOf

value:Any -> Type

Returns the type of the value.

isType

value:Any -> ttype:Type -> Bool

Checks whether a value conforms to a given type.

isSubtype

subtype:Type -> supertype:Type -> Bool

Checks whether a type is a subtype of another type.

Schemas and grammars

schema

value:Type -> Str

Returns the JSON schema of a type.

bnf

value:Type -> Str

Returns the BNF grammar of a type.

Annotations

setNote

value:Any -> annotation:Str? -> Any

Annotates a value.

getNote

value:Any -> Str?

Get a value's annotation.

Miscelleanous

bindMethod

value:Any -> func:(Any -> Any) -> Any -> Any

Binds a function to a value as a method.

uid

value:Any -> Int

Returns the unique value identifier.

mute

_:Any -> Null

Return null given any input.

dump

_:Null -> Null

Prints the current environment and its parents.

getEnv

_:Null -> {}

Returns the current environment.