assert
assert(value: any) -> any
panics if value is falsy
⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⡶⢦⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡔⢫⣮⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⡰⠑⠌⠄⡀⡆⠀⠀⠀⠀⠀⠀⠀⠀⢠⡞⣕⣱⣛⡻⠻⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣧⠐⠃⡀⢃⡙⡀⠀⠀⠀⠀⠀⠀⡰⣫⡞⢩⡞⠁⡀⠀⣟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⢹⣦⠁⡐⠠⠹⣄⠀⠀⠀⠀⠀⡔⢵⡟⠠⠋⡄⠀⠀⡘⠸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⡇⢢⠀⠘⣇⠀⠀⠀⣰⡫⣻⠀⠀⡸⠀⠀⢘⡒⢼⠠⠒⠚⠻⡍⠋⠛⠒⣶⢤⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡿⠡⡱⡙⢄⠌⢆⠀⢠⠟⡏⢸⡆⠀⠇⠀⣠⣪⠖⣿⠀⠀⠀⡆⠀⠀⠀⠀⠀⠅⢀⡙⢋⠙⠲⡦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠃⠼⡀⡄⣞⠄⣼⣾⣯⠢⣏⣰⠀⡰⣻⠅⣸⡿⠀⠀⡰⠀⣴⠁⢠⠂⡘⠐⠀⠀⠀⠀⠀⠀⠈⠲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡆⠄⡖⠅⢳⠎⢹⣿⣿⡾⡢⢻⣾⡸⢠⠇⠤⢫⣧⣇⡖⣷⡺⡫⡆⣡⠎⢀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠶⣄⡀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢾⢦⠃⠀⢃⣾⡛⢿⢻⠇⡨⣻⣷⣏⣠⠊⠍⡼⣿⡇⡘⢀⡕⡱⠀⡠⠂⣈⠔⢁⠔⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣢⡀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡶⢀⠄⠔⠀⠘⢻⣧⡟⠇⠘⠳⢨⡟⠁⠠⠊⣸⣿⡏⣰⡧⠛⠀⣤⠏⣠⠞⠁⠔⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⡄⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⢏⡐⠋⡰⢁⠞⡀⣼⠺⣧⡎⡔⠀⠈⠉⠀⠀⣰⡿⣿⣷⣿⣧⡾⢾⢛⣍⠌⣠⣤⡠⠄⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀ ⠀⠀⠀⠀⠀⢀⣠⣾⢫⢯⣿⢴⣽⣷⢆⣼⠟⡗⡀⡠⠟⠀⢀⠄⠀⠀⠀⣹⣾⣿⢏⣾⣩⣷⣟⣋⡞⠖⠋⠀⠀⠀⠂⠀⠐⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢱⡀ ⠀⠀⠀⠀⢠⡞⣣⣿⢣⣫⡿⣽⠎⢢⠿⢃⠎⠈⡁⠊⠀⡨⠃⠀⠠⢀⡨⠛⣩⣷⣷⠿⣫⡱⠟⠃⠀⠀⣀⡀⠄⠠⠤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠓ ⠀⠀⠀⢰⡏⣰⢃⠃⣼⡿⣿⠋⠀⠀⠀⠁⠀⠀⠀⢀⠜⠀⠠⠖⠂⠁⠀⠀⠘⣹⣿⡉⠋⣡⠔⠀⠀⠀⡀⠀⠀⠒⠐⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⣸⢴⢳⢹⣧⡟⠁⠃⢀⣔⣶⣦⡤⠀⠈⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣳⣿⠛⠒⠓⢀⠀⡀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⢠⡿⢸⣿⡖⣇⣇⠀⢴⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢯⣾⠟⠃⠀⠔⠁⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⣾⢁⣟⣷⣇⠻⠉⢇⠘⠯⣿⣿⡿⠛⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⢀⠼⣗⡊⠉⠉⣄⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⢸⡿⢟⣟⠫⢏⡆⠀⠨⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣷⡞⠶⠶⠟⠛⠄⠐⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⢸⣷⣹⠐⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠞⠀⠌⠐⠑⠦⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠈⢾⣿⣿⣴⣤⣧⡶⣦⣤⠐⠂⠤⠄⠀⠄⠀⠀⠀⠀⠀⠀⢀⡋⠉⠉⢤⣌⣈⠢⠀⠠⠤⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠘⣿⣿⣿⣿⣾⣷⣯⢧⠼⡢⠐⠂⠀⠀⠀⠀⠀⠀⠀⢠⠀⠀⠀⠰⠦⣿⠁⠒⠗⣤⡀⠀⢢⡀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀ ⠀⠀⠈⣿⣿⣆⣻⡿⣹⡀⣦⡚⢦⠁⠁⠀⠀⢠⠀⠐⠀⢐⠀⠀⠈⠂⢄⠙⢧⡍⠑⠠⡉⣷⣤⡠⢭⣆⠱⣕⡖⠂⠀⠀⠀⠀⠀⣤⣿⣷⡯⢍⡓⣤⠀⠀⠀⠀ ⠀⠀⠀⡘⠫⠝⠿⣿⣜⣧⣰⢎⢄⢡⠀⠐⠂⠀⠀⠀⠄⠠⢀⠦⣀⡐⠳⣦⣈⡌⣗⣄⣿⣮⡿⣿⡷⢿⢷⠕⡤⢧⡀⠀⠀⠀⣶⣿⣯⣈⡇⢷⠨⣢⡁⣦⡀⠀ ⠀⠀⠈⠀⠀⠀⠀⠀⠉⣧⣧⢥⣡⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢩⠏⠻⣮⡹⠦⣵⣼⣿⣿⣿⢿⡜⢾⣜⣦⣿⡜⢿⠢⢵⣤⣷⣿⣿⣏⠻⠿⠦⣄⣟⠁⠀⠈⢁ ⠀⠀⠀⠀⠀⠰⠀⠀⠘⠛⠛⠚⠛⣳⣶⣶⣄⠀⠢⡀⠠⠀⢠⠀⢀⢰⣿⣌⣧⣿⡿⠿⠟⠉⠖⢳⠈⠄⡀⢩⢿⣆⣻⣳⣿⣿⣿⣿⣿⢿⡀⣀⣸⡇⢀⠠⠖⠁ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣿⣷⣿⣦⣶⣿⣤⣾⣾⣿⣿⠟⢁⠀⠀⠀⣰⡆⢀⠰⡏⢱⣾⡶⠿⠛⠋⠁⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠛⠛⠟⠿⠿⠿⠿⠿⠿⠿⠿⠟⠒⠻⣀⡶⣳⡿⡇⢀⣿⣣⠟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠂⠤⠏⠀⠄⠒⠋⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
auto-generated from source
you'll see some metamethods here (functions prepended with `__`)
`number.__call("42")` is `number(42)`
`string.__index("qwer", 2)` is `string[2]`
welcome to revo's standard library
assert(value: any) -> any
panics if value is falsy
assert_eq(a: any, b: any) -> any
panics if values are not equal
chan(?capacity: num...) -> {:chan, num}
creates a new channel with optional buffer size
cwd() -> string
returns current working directory path
debug_info() -> {flags: {dump: bool, trace: bool, instr: bool, stack: bool}, fiber_id: num, pc: num, stack_depth: num, frame_depth: num, program_len: num, has_debug_info: bool, source_name: string?, source: string?, span_count: num, panic_message: string?}
returns debug info as a table
exit(status: num) -> never
exists the program with a status
expect(value: any) -> !any
used in tests, returns value or {:err, :ExpectFailed} tuple
expect_eq(a: any, b: any) -> !any
returns value or {:err, :NotEqual} tuple if values are not equal
fmt(format: string, args: any...) -> string
formats a string with format specifiers ~ %v is value (plain) ~ %? is debug (quoted strings, multilined tables) ~ %p is pretty (debug with colors)
string literals also support `#{expr}`, `#{expr:?}`, and `#{expr:p}` interpolation
you likely want to use them instead
gensym() -> string
returns a fresh unique symbol-like string, for macro hygiene
get_meta(value: any) -> table | :undef
returns metatable of value or :undef
getenv(name: string) -> string?
returns value of environment variable, or nil if not set
hash(val: any) -> num
hashes any value
import(path: string) -> any
imports a revo module by path
input(?opts: os.InputOpts...) -> !string
reads one line from stdin, or until a custom delimiter (?opts: { delimiter: string|:nil|:eof })
inspect(value: any) -> any
prints one value and returns it back
join(handle: {:fiber, num}) -> any
blocks until the fiber completes and returns its result
len(value: any) -> num
returns length of string or table
panic(args: any...) -> never
panics with given message
print(args: any...) -> :ok
prints values to stdout with space separator
recv(chan: {:chan, num}) -> any
receives value from channel, parks if empty
send(chan: {:chan, num}, value: any) -> :ok
sends value to channel
set_debug(flags: {dump: bool?, trace: bool?, instr: bool?, stack: bool?}) -> :ok
sets debug flags from a table (all fields default to :false)
set_meta(value: any, meta: table | :undef) -> any
sets metatable of value
setenv(name: string, value: string) -> :ok
sets an environment variable, returns :ok
sleep(ms: num) -> :parked
sleeps current fiber for given milliseconds
system(args: table<string>) -> !{string, string}
runs a subprocess and returns (stdout, stderr)
to_iter(obj: any) -> function
wraps any iterable in a zero-arg callable built-in types (string, table) get a position-based iterator functions return as-is (already callable) tables with __iter metamethod call __iter(obj)
typeof(value: any) -> atom
returns type of value as atom: nil, num, string, atom, function, table, opaque, resource
command-line arguments parsing
(value)
alias for ```revo {err: argparse.ResultMsg?, flags: table<string, string | bool>?, commands: table<string, bool>?, positionals: table<string, string>?, leftover: table<string>?} ```
(value)
alias for ```revo {token: string, message: string} ```
a parse error, token plus its message
argparse.parse(callback: function, argv: table) -> argparse.Opts
Usage: argparse.parse BUILDER ARGS Parse CLI args with flags, options, commands, and positionals. Subcommands: p:flag(name: atom, opts: table) p:option(name: atom, opts: table) p:command(name: atom, opts: table) p:positional(name: atom, opts: table) All arguments to opts are optional: short string the shorthand for the argument, like -v description string description to be displayed in the usage terminal bool stop parsing after this arg is filled passthrough bool pass remaining args to child prefix bool treat the option as a prefix Examples: ./args.rv ./args.rv -v -o out.txt main.rv ./args.rv compile -v ./args.rv --unknown Output status: result.err: nil | { token = string, message = string } result.flags: table of flag names to values result.commands: table of command names to booleans result.positionals: table of positional names to values result.leftover: table of unconsumed args Report bugs to <https://github.com/if-not-nil/revo/issues>
argparse.usage(result: argparse.Opts) -> string
format a usage string from a parse result
compress & decompress stuff
compress.base64_decode(data: string) -> !string
decodes standard base64 string
compress.base64_encode(data: string) -> string
encodes data as standard base64 with padding
compress.base64url_decode(data: string) -> !string
decodes url-safe base64 string
compress.base64url_encode(data: string) -> string
encodes data as url-safe base64 without padding
compress.deflate(data: string) -> !string
compresses data using raw deflate
compress.gzip_compress(data: string) -> !string
compresses data using gzip format
compress.gzip_decompress(data: string) -> !string
decompresses gzip data
compress.inflate(data: string) -> !string
decompresses raw deflate data
compress.lzma_decompress(data: string) -> !string
decompresses lzma data
compress.xz_decompress(data: string) -> !string
decompresses xz data
compress.zlib_compress(data: string) -> !string
compresses data using zlib format
compress.zlib_decompress(data: string) -> !string
decompresses zlib data
compress.zstd_decompress(data: string) -> !string
decompresses zstd data
encode values as csv and decode csvs back into revo values
(value)
alias for ```revo {?delimiter: string, ?terminator: string, ?quote: string?, ?bom: bool} ```
csv encoding and decoding options
csv.decode(source: string, ?opts: csv.Opts) -> !any
decodes csv string into revo value CSVs can have options determining the delimiter (default ","), terminator (default "\r\n"), bom (unicode flag, default as off), and quote (default '"').
repl
rεvo > global dialect = { delimiter = ";", terminator = "~", quote = "*", bom = :false }
rεvo > csv.encode({{"hi", "wow"}, {'yay; so cool!', "aaa"}}, dialect)
{:ok, "hi;wow~*yay; so cool!*;aaa~"}
rεvo > "hi;wow~*yay; so cool!*;aaa~" |> csv.decode(dialect)
{ { "hi", "wow" }, { "yay; so cool!", "aaa" } }
csv.encode(value: any, ?opts: csv.Opts) -> !string
encodes revo value as csv string CSVs can have options determining the delimiter (default ","), terminator (default "\r\n"), bom (unicode flag, default as off), and quote (default '"').
repl
rεvo > global dialect = { delimiter = ";", terminator = "~", quote = "*", bom = :false }
rεvo > csv.encode({{"hi", "wow"}, {'yay; so cool!', "aaa"}}, dialect)
{:ok, "hi;wow~*yay; so cool!*;aaa~"}
rεvo > "hi;wow~*yay; so cool!*;aaa~" |> csv.decode(dialect)
{ { "hi", "wow" }, { "yay; so cool!", "aaa" } }
dataframe functions
dataframe.select(input: table<string, table<any>>, columns: table<string>) -> table<string, table<any>>
selects only the given columns for a new dataframe, in the input order
you already know what it is (might merge into time, idk)
datetime.today() -> string
returns current date in UTC using ISO 8601 (YYYY-MM-DD) date format
dynamic c calls, posix only
ffi.errno() -> number
errno from the last ffi call on this vm
ffi.func(lib: any, name: string, ret: atom, args: table) -> any
declare a c function, call the handle: return type + arg types as atoms
ffi.load(path: string) -> any
open a shared library, returns a handle
ffi.varfunc(lib: any, name: string, ret: atom, fixed: table, total: number) -> any
declare a variadic c function: fixed prefix types + total count
filesystem access & ops
file.close(self: table) -> !atom
closes a file handle table this is currently a logical close for wrapper handles
file.read(self: table) -> !string
reads the full file contents as a string
file.readdir(self: table) -> !table<{name: string, kind: atom}>
returns table of directory entries for the dir handle's path
file.stat(self: table, follow: bool?) -> !fs.Stat
get file metadata as a table; follow optional, defaults to :true: :false leaves symlinks alone
file.write(self: table, data: string, append: bool?, permissions: num?) -> !num
overwrites the file with the provided string, or appends when append is :true optional permissions default to the platform file default
filesystem access & ops
(value)
alias for ```revo {size: num, kind: atom, permissions: num, mtime: num, atime: num, ctime: num} ```
file metadata as returned by file.stat and fs.stat
fs.chdir(path: string) -> !atom
changes cwd to the given path
fs.copy(src: string, dst: string) -> !atom
copies a file to a new path, overwriting the destination
fs.exists?(path: string) -> bool
does path exist? answers :false when missing, raises on unexpected io errors
fs.glob(pattern: string, recursive: bool?, depth_limit: num?) -> !table
returns a list of files using pattern matching rules similar to the UNIX shell, if no matches are found then the table will be empty. recursive optional, defaults to :false: :true causes "**" to match all directories and subdirectories until it reaches an endpoint, this can be quite cpu heavy on large directories depth_limit optional, defaults to 100: this is used to set an endpoint where glob must stop matching files after a certain recursion depth.
fs.mkdir(path: string, parents: bool?, permissions: num?) -> !atom
creates a directory; parents optional, defaults to :false: :true creates missing parents like `mkdir -p`. permissions optional, platform default when omitted
fs.open(path: string, mode: string?) -> !table
wraps a path in a file handle table mode is optional, defaults to "r": "r" opens an existing path, "w" creates or truncates a file, "a" creates or keeps a file use `file.close()` when you're done with the handle
fs.readdir(path: string) -> !table<{name: string, kind: atom}>
returns table of directory entries
fs.remove(path: string, recursive: bool?) -> !atom
removes a file or directory at path recursive is optional, defaults to :false: removes a file or empty directory only, :true deletes the whole tree
fs.rename(old_path: string, new_path: string) -> !atom
renames a file or directory
fs.stat(path: string, follow: bool?) -> !fs.Stat
get file metadata as a table from a path; follow optional, defaults to :true
fs.touch(path: string) -> !atom
ensures a file exists, creating it empty when missing and leaving existing entries alone
http
(value)
alias for ```revo {?headers: table<string, http.HeaderValue>, ?body: string, ?max_redirects: num} ```
fetch options
http.fetch(method: :get | :post | :put | :delete | :head | :options | :patch | :trace, url: any, ?opts: http.FetchOpts) -> !string
fetch an http request the default Content-Type is json fetch options are `headers` (key-value table), `body`, and `max_redirects` any fetch option can be `:nil` setting `max_redirects` to a number will follow redirects for the specified count. `:nil` leaves redirection up to the caller. examples:
revo
http.fetch(:get, "https://example.com")
http.fetch(:post, "https://example.com", {
body = "{\"foo\":\"bar\"}",
max_redirects = 3
})
lazy iterators: range, mapping, filtering, folding and chaining
iter.all?(collection: any, pred: function) -> bool
returns true if function returns true for all elements iter.all?({1, 2, 3}, fn(x) x > 0)
iter.any?(collection: any, pred: function) -> bool
returns true if function returns true for any element iter.any?({1, 2, 3}, fn(x) x > 2)
iter.chunk(collection: any, n: num) -> function
returns a lazy iterator of n-element table chunks iter.collect(iter.chunk({1, 2, 3, 4, 5}, 2)) # {{1, 2}, {3, 4}, {5}}
iter.collect(iterable: any) -> table
collects all values from an iterable into a table iter.collect(iterable)
iter.collect_string(iterable: any) -> string
collects string/num elements from an iterable into a string numbers are clamped to byte values iter.collect_string(iter.filter("hello", fn(c) c != "l"))
iter.count(collection: any, ?pred: function) -> num
returns the number of elements, or of those where pred is truthy iter.count({1, 2, 3, 4}) iter.count({1, 2, 3, 4}, fn(x) x > 2)
iter.drop(collection: any, n: num) -> function
returns a lazy iterator without the first n elements iter.collect(iter.drop({1, 2, 3, 4}, 2))
iter.each(collection: any, fn: function) -> :ok
iterates over elements, calling function for side effects, returns :ok an arity-2 fn receives (value, index/key) iter.each({a = 1}, fn(v, k) print(k, v))
iter.enumerate(collection: any) -> function
returns a lazy iterator of (index, value) pairs iter.collect(iter.enumerate({5, 7})) # {{0, 5}, {1, 7}}
iter.filter(collection: any, fn: function) -> function
returns a lazy iterator that only yields values where fn is truthy an arity-2 fn receives (value, index/key) iter.collect(iter.filter({1, 2, 3, 4}, fn(x) x > 2))
iter.find(collection: any, fn: function) -> any?
returns first element where function returns true, or nil iter.find({1, 2, 3, 4}, fn(x) x > 2)
iter.flat_map(collection: any, fn: function) -> function
maps each element to an iterable and yields its elements lazily iter.collect(iter.flat_map({1, 2}, fn(x) {x, x * 10})) # {1, 10, 2, 20}
iter.fold(collection: any, fn: function) -> any?
like reduce but without an initial value; first element seeds the fold returns nil for empty collections iter.fold({1, 2, 3, 4}, fn(acc, x) acc + x)
iter.map(collection: any, fn: function) -> function
returns a lazy iterator that transforms each element an arity-2 fn receives (value, index/key); materialize with iter.collect() iter.collect(iter.map({1, 2, 3}, fn(x) x * 2))
iter.range(end: num, rest: num...) -> function
generates a lazy arithmetic sequence range(3) # 0, 1, 2 range(1, 4) # 1, 2, 3 range(0, 10, 2) # 0, 2, 4, 6, 8 range(5, 0, -1) # 5, 4, 3, 2, 1
iter.reduce(collection: any, fn: function, init: any) -> any
folds/accumulates elements using function and initial value iter.reduce({1, 2, 3, 4}, fn(acc, x) acc + x, 0) iter.reduce(iter.map({1, 2}, fn(x) x * 2), fn(acc, x) acc + x, 0)
iter.sum(collection: any) -> num
sums numeric elements, skipping non-numbers iter.sum({1, 2, "x", 3})
iter.take(collection: any, n: num) -> function
returns a lazy iterator of the first n elements iter.collect(iter.take({1, 2, 3, 4}, 2))
iter.zip(first: any, second: any, rest: any...) -> function
returns a lazy iterator of pairs, one element from each iterable takes two or more, stops at the shortest iter.collect(iter.zip({1, 2}, {3, 4})) # {{1, 3}, {2, 4}}
encode values as json and decode json back into revo values
json.decode(source: string) -> !any
decodes json string into revo value
json.encode(value: any, ?pretty: bool) -> !string
encodes value as json string; enabling `pretty` will emit indented json
numeric math
math.abs(x: num) -> num
absolute value
math.acos(x: num) -> num
arc-cosine of x (x in radians)
math.acosh(x: num) -> num
hyperbolic arc-cosine of x (x in radians)
math.asin(x: num) -> num
arc-sine of x (x in radians)
math.asinh(x: num) -> num
hyperbolic arc-sine of x (x in radians)
math.atan(x: num) -> num
arc-tangent of x (x in radians)
math.atan2(y: num, x: num) -> num
arc-tangent of y and x (y and x in radians)
math.atanh(x: num) -> num
hyperbolic arc-tangent of x (x in radians)
math.ceil(x: num) -> num
ceiling of x
math.close?(x: num, y: num, places: num) -> bool
test whether two values are close within the given number of decimal places
math.cos(x: num) -> num
cosine of x (x in radians)
math.cosh(x: num) -> num
hyperbolic cosine of x (x in radians)
math.exp(x: num) -> num
e raised to x
math.floor(x: num) -> num
floor of x
math.hypot(x: num, y: num) -> num
hypotenuse of sides x and y
math.log(x: num) -> num
natural logarithm, panics if x <= 0
math.max(first: num, args: num...) -> num
max of all arguments, at least one required
math.min(first: num, args: num...) -> num
min of all arguments, at least one required
math.pow(base: num, exponent: num) -> num
base raised to exponent
math.sign(value: num) -> num
sign of value (-1, 0, 1)
math.sin(x: num) -> num
sine of x (x in radians)
math.sinh(x: num) -> num
hyperbolic sine of x (x in radians)
math.sqrt(x: num) -> num
square root, errors if x is negative
math.tan(x: num) -> num
tangent of x (x in radians)
math.tanh(x: num) -> num
hyperbolic tangent of x (x in radians)
tcp sockets: connect, listen, accept, send and receive
net.connect(host: string, port: num) -> !table
connects to a remote host and port, returns a socket handle
net.listen(port: num, ?backlog: num...) -> !table
listens for incoming connections on the given port, returns server socket
global number helpers, calllable as `1337:nan?` and `number.nan?(1337)`
number.__call(value: string) -> number
converts value to number: number("12") => 12
number.abs(self: number) -> number
absolute value
number.ceil(self: number) -> number
smallest integer >= self
number.finite?(self: number) -> bool
checks if number is finite
number.floor(self: number) -> number
largest integer <= self
number.inf?(self: number) -> bool
checks if number is infinite
number.nan?(self: number) -> bool
checks if number is NaN
number.round(self: number) -> number
rounds to nearest integer
(value)
alias for ```revo {?delimiter: string | :nil | :eof} ```
read input options
regular expressions!
re.__call(pattern: string) -> table
compile a regex pattern into a reusable handle
re.compile(pattern: string) -> table
compile a regex pattern into a reusable handle
re.find(regex: table | string, haystack: string) -> string?
return first match or nil; pass a string for one-shot compile
re.find_all(regex: table | string, haystack: string) -> function
return an iterator over all matches; pass a string for one-shot compile
re.free(regex: table) -> :nil
free a compiled regex handle
re.is_match(regex: table | string, haystack: string) -> bool
test if regex matches anywhere in haystack; pass a string for one-shot compile
the revo metaprogramming lib
revo.compile(code: string) -> !string
builds it as a module, gives you back its' bytecode in a string the string is only useful for writing to a file or executing
revo.dofile(path: string) -> !any
reads the file and evaluates it as a module, gives you back its' return value like eval but the source comes from a file, relative paths resolve against the current module's directory like import, then cwd
revo.eval(code: string) -> !any
evaluates it as a module, gives you back its' return value you can treat it as a function's body
revo.threads() -> num
worker thread count (see --threads)
revo.version() -> string
version of your revo installation, like "revo v1.2.3"
pseudo-random numbers with a settable seed
rng.choice<T>(input: table<T>) -> T?
Returns a random element from a table, or :nil if empty (note: this function *ignores* key value pairs.)
rng.rand(upper_bound: num) -> num
Returns a random integer in the range [0, upper_bound]
rng.rand_float() -> num
Returns a random float in the range [0, 1]
rng.range(lower_bound: num, upper_bound: num) -> num
Returns a random integer in the range [lower_bound, upper_bound]
rng.revert_seed()
Reverts seed back to using the current time at the time of generation.
rng.set_seed(seed: num)
Statically sets the seed used for generation of pseudo-random numbers.
tcp sockets: connect, listen, accept, send and receive
(value)
alias for ```revo {?mode: :read_some | :read_all | :read_line, ?max_bytes: num, ?delimiter: string} ```
recv options
socket.accept(self: table) -> !table
accepts an incoming client connection on a server socket
socket.close(self: table) -> !atom
closes the socket
socket.recv(self: table, opts: socket.RecvOpts) -> !string
receives data according to opts
socket.send(self: table, data: string) -> !num
sends data over the socket, returns number of bytes sent
statistics functions
stats.correlation(input1: table<num>, input2: table<num>) -> num
correlation coefficient of the input data
stats.covariance(input1: table<num>, input2: table<num>) -> num
population covariance of the input data
stats.frequencies(input: table<any>) -> table<any, num>
counts frequencies of elements in an array table and returns a mapping of elements to their counts
stats.geomean(input: table<num>) -> num
calculates the geometric mean of an array of numbers
stats.intercept(input1: table<num>, input2: table<num>) -> num
intercept of the regression of the input data
stats.kurtosis(input: table<num>) -> num
population kurtosis of the input data
stats.mean(input: table<num>) -> num
calculates the arithmetic mean of an array of numbers
stats.median(input: table<num>) -> num
middle value of input data
stats.mode(input: table<any>) -> any
most frequent occuring value of input data
stats.regression(input1: table<num>, input2: table<num>) -> {n: num, sum_of_products: num, slope: num, intercept: num, correlation: num, covariance: num, sample_covariance: num}
table of regression statistics of the input data
stats.sample_covariance(input1: table<num>, input2: table<num>) -> num
sample covariance of the input data
stats.sample_kurtosis(input: table<num>) -> num
sample kurtosis of the input data
stats.sample_skewness(input: table<num>) -> num
sample skewness of the input data
stats.sample_stdev(input: table<num>) -> num
sample standard deviation of the input data
stats.sample_variance(input: table<num>) -> num
sample variance of the input data
stats.skewness(input: table<num>) -> num
population skewness of the input data
stats.slope(input1: table<num>, input2: table<num>) -> num
slope of the regression of the input data
stats.statistics(input: table<num>) -> {n: num, frequencies: table, mean: num, median: num, mode: num, stdev: num, sample_stdev: num, variance: num, sample_variance: num, skewness: num, sample_skewness: num, kurtosis: num, sample_kurtosis: num}
table of all statistics of the input data
stats.stdev(input: table<num>) -> num
population standard deviation of the input data
stats.variance(input: table<num>) -> num
population variance of the input data
global string helpers, calllable as `"hello world":split(" ")` and `string.split("hello world", " ")`
string.__call(value: any) -> string
converts value to string: string(x)
string.alnum?(self: string) -> bool
checks if all characters in the string are alphanumeric
string.alpha?(self: string) -> bool
checks if all characters in the string are alphabetic
string.ascii(self: string) -> num
returns ASCII code of first character
"a":ascii() => 97
string.concat(self: string, other: string) -> string
concatenates two strings
string.contains?(self: string, substr: string) -> bool
checks if string contains substring
string.ends_with?(self: string, suffix: string) -> bool
checks if string ends with suffix
string.index_of(self: string, substr: string) -> num?
ret 0-based index of substring or nil
string.join(table: table<string>, sep: string) -> string
joins table elements into string with separator
string.len(self: string) -> num
returns length of string
string.lower(self: string) -> string
converts string to lowercase
string.lower?(self: string) -> bool
checks if all characters in the string are lower case
string.of_ascii(code: num) -> string
creates string from ASCII code(s)
of_ascii(97) => "a"
string.punct?(self: string) -> bool
checks if all characters in the string are punctuation
string.repeat(self: string, n: num) -> string
repeats string n times
string.replace(self: string, old: string, new: string) -> string
replaces all occurrences of old with new
string.reverse(self: string) -> string
reverses the string
string.split(self: string, delim: string) -> table<string>
splits string by delimiter into table
string.starts_with?(self: string, prefix: string) -> bool
checks if string starts with prefix
string.sub(self: string, start: num, length: num) -> string
extracts substring from start with given length
string.table(self: string) -> table<string>
converts string to table of characters
"asdf":table() => {"a", "s", "d", "f"}
string.trim(self: string) -> string
trims whitespace from both ends
string.upper(self: string) -> string
converts string to uppercase
string.upper?(self: string) -> bool
checks if all characters in the string are upper case
string.whitespace?(self: string) -> bool
checks if all characters in the string are whitespace
string.with(self: string, idx: num, char: string | num) -> string
replaces character at index with given char or byte index is 0-based
global table helpers, calllable as `{1, 2}:at(0)` and `table.at({1, 2}, 0)`
table.alen(self: table) -> num
returns length of table array part only
table.at<T>(self: table<T>, index: num) -> T | :undef
gets array element at 0-based index, metatable-ignoring returns :undef when out of range
table.at?(self: table, index: num) -> bool
whether a 0-based index holds an array element, metatable-ignoring
table.contains?(self: table, value: any) -> bool
checks if table contains value
table.copy<T>(self: table<T>) -> table<T>
creates shallow copy of table
table.count_of(self: {}, search_val: any) -> num
returns the number of times a specified value appears in a table's array part
table.deep_copy<T>(self: table<T>) -> table<T>
creates a deep copy of the table, duplicating nested tables (cycles map to their in-progress copy)
table.empty?(self: table) -> bool
reports whether the table holds no entries at all
table.flatten(self: table<any>) -> table<any>
flattens nested tables into single array (non-table elements pass through)
table.get_meta(self: table) -> table | :undef
returns metatable of value or :undef
table.index_of(self: {}, value: any) -> num?
returns 0-based index of value in the array part, or nil if not found
table.insert<T>(self: table<T>, pos: num, value: T) -> :ok
inserts value at position, shifting elements right
table.join(self: table, delim: string) -> string
joins array elements with delimiter
table.key<V>(self: table<V>, key: any) -> V | :undef
gets map value, metatable-ignoring returns :undef if key missing
table.key?(self: table, key: any) -> bool
whether a key exists, metatable-ignoring
table.keys<K, V>(self: table<K, V>) -> table<K>
returns all keys as table (array indices + hash keys)
table.klen(self: table) -> num
returns length of table keyed entries only
table.last(self: table) -> table
the array part's last element
table.len(self: table) -> num
returns total length of table (array part + keyed entries)
table.merge<K, V>(self: table<K, V>, other: table<K, V>) -> table<K, V>
merges second table into first later values overwrite earlier ones
table.pop<T>(self: table<T>) -> T | :undef
removes and returns the last array element, or :undef if empty
table.push(self: table, values: any...) -> table
inserts elements as last
table.rawget(self: table, key: any) -> any | :undef
gets value without metamethods returns :undef if key missing
table.rawset(self: table, key: any, value: any) -> table
sets value without metamethods
table.remove<T>(self: table<T>, key: any) -> T
removes element at position or key, returns removed value
table.repeat<T>(self: table<T>, n: num) -> table<T>
repeats table array part n times
table.reverse<T>(self: table<T>) -> table<T>
reverses table array part in place
table.set_meta(self: table, meta: :undef | table) -> table
sets the metatable of the table, `:undef` clears it
table.slice<T>(self: table<T>, start: num, end: num...) -> table<T>
returns a new table with array items [start, end), end defaults to the array length, bounds clamp
table.sort<T>(self: table<T>) -> table<T>
sorts table array part in ascending order (numbers < strings)
table.sort_by(self: table, fn: function) -> table
sorts table array part using comparison function fn(a, b) -> bool (true if a < b)
table.unique<T>(self: table<T>) -> table<T>
removes duplicate elements
table.unwrap<T>(self: {:ok, T} | table) -> T
unwraps result, panics if not :ok
table.unwrap_err<T>(self: {:err, T} | table) -> T
extracts error from result, panics if not :err
table.update<T>(self: table<T>, key: any, fn: function) -> table<T>
applies fn to the value at key (missing reads as :nil) and stores the result back, returns self
table.values<K, V>(self: table<K, V>) -> table<V>
returns all values as table
clocks
time.monotonic() -> num
returns monotonic clock in milliseconds
time.monotonic_ns() -> num
returns monotonic clock in nanoseconds since the first call
time.now() -> num
returns current wall-clock time in milliseconds
time.now_ns() -> num
returns current wall-clock time in nanoseconds since the first call
parse uri strings
(value)
alias for ```revo {?scheme: string, ?user: string, ?host: string, ?path: string, ?query: table<string, string | num>, ?fragment: string, ?port: num} ```
parts of a uri; encode tolerates absent fields, decode fills them
uri.decode(value: string) -> !uri.Uri
parses string as uri examples:
repl
rεvo > uri.decode("https://example.com/hi/there?search&page=3#woah")
{ :ok, {
scheme = "https",
host = "example.com",
path = "/hi/there",
query = { "search", page = 3 },
fragment = "woah"
} }
uri.encode(value: uri.Uri) -> !string
formats uri table as string examples:
repl
rεvo > uri.encode({
> scheme = "https",
> user = :nil,
> host = "example.com",
> path = "/hi/there",
> query = { "search", "page" = 3 },
> fragment = :nil
> })
{ :ok, "https://example.com/hi/there?search&page=3" }