⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⡶⢦⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡔⢫⣮⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⡰⠑⠌⠄⡀⡆⠀⠀⠀⠀⠀⠀⠀⠀⢠⡞⣕⣱⣛⡻⠻⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣧⠐⠃⡀⢃⡙⡀⠀⠀⠀⠀⠀⠀⡰⣫⡞⢩⡞⠁⡀⠀⣟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢹⣦⠁⡐⠠⠹⣄⠀⠀⠀⠀⠀⡔⢵⡟⠠⠋⡄⠀⠀⡘⠸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⡇⢢⠀⠘⣇⠀⠀⠀⣰⡫⣻⠀⠀⡸⠀⠀⢘⡒⢼⠠⠒⠚⠻⡍⠋⠛⠒⣶⢤⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡿⠡⡱⡙⢄⠌⢆⠀⢠⠟⡏⢸⡆⠀⠇⠀⣠⣪⠖⣿⠀⠀⠀⡆⠀⠀⠀⠀⠀⠅⢀⡙⢋⠙⠲⡦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡆⠃⠼⡀⡄⣞⠄⣼⣾⣯⠢⣏⣰⠀⡰⣻⠅⣸⡿⠀⠀⡰⠀⣴⠁⢠⠂⡘⠐⠀⠀⠀⠀⠀⠀⠈⠲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡆⠄⡖⠅⢳⠎⢹⣿⣿⡾⡢⢻⣾⡸⢠⠇⠤⢫⣧⣇⡖⣷⡺⡫⡆⣡⠎⢀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠶⣄⡀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢾⢦⠃⠀⢃⣾⡛⢿⢻⠇⡨⣻⣷⣏⣠⠊⠍⡼⣿⡇⡘⢀⡕⡱⠀⡠⠂⣈⠔⢁⠔⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣢⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡶⢀⠄⠔⠀⠘⢻⣧⡟⠇⠘⠳⢨⡟⠁⠠⠊⣸⣿⡏⣰⡧⠛⠀⣤⠏⣠⠞⠁⠔⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⡄⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⢏⡐⠋⡰⢁⠞⡀⣼⠺⣧⡎⡔⠀⠈⠉⠀⠀⣰⡿⣿⣷⣿⣧⡾⢾⢛⣍⠌⣠⣤⡠⠄⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀
⠀⠀⠀⠀⠀⢀⣠⣾⢫⢯⣿⢴⣽⣷⢆⣼⠟⡗⡀⡠⠟⠀⢀⠄⠀⠀⠀⣹⣾⣿⢏⣾⣩⣷⣟⣋⡞⠖⠋⠀⠀⠀⠂⠀⠐⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢱⡀
⠀⠀⠀⠀⢠⡞⣣⣿⢣⣫⡿⣽⠎⢢⠿⢃⠎⠈⡁⠊⠀⡨⠃⠀⠠⢀⡨⠛⣩⣷⣷⠿⣫⡱⠟⠃⠀⠀⣀⡀⠄⠠⠤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠓
⠀⠀⠀⢰⡏⣰⢃⠃⣼⡿⣿⠋⠀⠀⠀⠁⠀⠀⠀⢀⠜⠀⠠⠖⠂⠁⠀⠀⠘⣹⣿⡉⠋⣡⠔⠀⠀⠀⡀⠀⠀⠒⠐⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣸⢴⢳⢹⣧⡟⠁⠃⢀⣔⣶⣦⡤⠀⠈⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣳⣿⠛⠒⠓⢀⠀⡀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢠⡿⢸⣿⡖⣇⣇⠀⢴⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢯⣾⠟⠃⠀⠔⠁⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣾⢁⣟⣷⣇⠻⠉⢇⠘⠯⣿⣿⡿⠛⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⢀⠼⣗⡊⠉⠉⣄⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢸⡿⢟⣟⠫⢏⡆⠀⠨⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣷⡞⠶⠶⠟⠛⠄⠐⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢸⣷⣹⠐⠁⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠞⠀⠌⠐⠑⠦⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠈⢾⣿⣿⣴⣤⣧⡶⣦⣤⠐⠂⠤⠄⠀⠄⠀⠀⠀⠀⠀⠀⢀⡋⠉⠉⢤⣌⣈⠢⠀⠠⠤⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠘⣿⣿⣿⣿⣾⣷⣯⢧⠼⡢⠐⠂⠀⠀⠀⠀⠀⠀⠀⢠⠀⠀⠀⠰⠦⣿⠁⠒⠗⣤⡀⠀⢢⡀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀
⠀⠀⠈⣿⣿⣆⣻⡿⣹⡀⣦⡚⢦⠁⠁⠀⠀⢠⠀⠐⠀⢐⠀⠀⠈⠂⢄⠙⢧⡍⠑⠠⡉⣷⣤⡠⢭⣆⠱⣕⡖⠂⠀⠀⠀⠀⠀⣤⣿⣷⡯⢍⡓⣤⠀⠀⠀⠀
⠀⠀⠀⡘⠫⠝⠿⣿⣜⣧⣰⢎⢄⢡⠀⠐⠂⠀⠀⠀⠄⠠⢀⠦⣀⡐⠳⣦⣈⡌⣗⣄⣿⣮⡿⣿⡷⢿⢷⠕⡤⢧⡀⠀⠀⠀⣶⣿⣯⣈⡇⢷⠨⣢⡁⣦⡀⠀
⠀⠀⠈⠀⠀⠀⠀⠀⠉⣧⣧⢥⣡⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢩⠏⠻⣮⡹⠦⣵⣼⣿⣿⣿⢿⡜⢾⣜⣦⣿⡜⢿⠢⢵⣤⣷⣿⣿⣏⠻⠿⠦⣄⣟⠁⠀⠈⢁
⠀⠀⠀⠀⠀⠰⠀⠀⠘⠛⠛⠚⠛⣳⣶⣶⣄⠀⠢⡀⠠⠀⢠⠀⢀⢰⣿⣌⣧⣿⡿⠿⠟⠉⠖⢳⠈⠄⡀⢩⢿⣆⣻⣳⣿⣿⣿⣿⣿⢿⡀⣀⣸⡇⢀⠠⠖⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣿⣷⣿⣦⣶⣿⣤⣾⣾⣿⣿⠟⢁⠀⠀⠀⣰⡆⢀⠰⡏⢱⣾⡶⠿⠛⠋⠁⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠛⠛⠟⠿⠿⠿⠿⠿⠿⠿⠿⠟⠒⠻⣀⡶⣳⡿⡇⢀⣿⣣⠟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠂⠤⠏⠀⠄⠒⠋⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  

revo's core library

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

globals

29 entries

assert

assert(value: any) -> any

panics if value is falsy

assert_eq

assert_eq(a: any, b: any) -> any

panics if values are not equal

chan

chan(?capacity: num...) -> {:chan, num}

creates a new channel with optional buffer size

cwd

cwd() -> string

returns current working directory path

debug_info

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

exit(status: num) -> never

exists the program with a status

expect

expect(value: any) -> !any

used in tests, returns value or {:err, :ExpectFailed} tuple

expect_eq

expect_eq(a: any, b: any) -> !any

returns value or {:err, :NotEqual} tuple if values are not equal

fmt

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

gensym() -> string

returns a fresh unique symbol-like string, for macro hygiene

get_meta

get_meta(value: any) -> table | :undef

returns metatable of value or :undef

getenv

getenv(name: string) -> string?

returns value of environment variable, or nil if not set

hash

hash(val: any) -> num

hashes any value

import

import(path: string) -> any

imports a revo module by path

input

input(?opts: os.InputOpts...) -> !string

reads one line from stdin, or until a custom delimiter (?opts: { delimiter: string|:nil|:eof })

inspect

inspect(value: any) -> any

prints one value and returns it back

join

join(handle: {:fiber, num}) -> any

blocks until the fiber completes and returns its result

len

len(value: any) -> num

returns length of string or table

panic

panic(args: any...) -> never

panics with given message

print

print(args: any...) -> :ok

prints values to stdout with space separator

recv

recv(chan: {:chan, num}) -> any

receives value from channel, parks if empty

send

send(chan: {:chan, num}, value: any) -> :ok

sends value to channel

set_debug

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

set_meta(value: any, meta: table | :undef) -> any

sets metatable of value

setenv

setenv(name: string, value: string) -> :ok

sets an environment variable, returns :ok

sleep

sleep(ms: num) -> :parked

sleeps current fiber for given milliseconds

system

system(args: table<string>) -> !{string, string}

runs a subprocess and returns (stdout, stderr)

to_iter

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

typeof(value: any) -> atom

returns type of value as atom: nil, num, string, atom, function, table, opaque, resource

modules

module argparse

command-line arguments parsing
4 entries

Opts

(value)

alias for ```revo {err: argparse.ResultMsg?, flags: table<string, string | bool>?, commands: table<string, bool>?, positionals: table<string, string>?, leftover: table<string>?} ```

ResultMsg

(value)

alias for ```revo {token: string, message: string} ```

a parse error, token plus its message

parse

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>

usage

argparse.usage(result: argparse.Opts) -> string

format a usage string from a parse result

module compress

compress & decompress stuff
13 entries

base64_decode

compress.base64_decode(data: string) -> !string

decodes standard base64 string

base64_encode

compress.base64_encode(data: string) -> string

encodes data as standard base64 with padding

base64url_decode

compress.base64url_decode(data: string) -> !string

decodes url-safe base64 string

base64url_encode

compress.base64url_encode(data: string) -> string

encodes data as url-safe base64 without padding

deflate

compress.deflate(data: string) -> !string

compresses data using raw deflate

gzip_compress

compress.gzip_compress(data: string) -> !string

compresses data using gzip format

gzip_decompress

compress.gzip_decompress(data: string) -> !string

decompresses gzip data

inflate

compress.inflate(data: string) -> !string

decompresses raw deflate data

lzma_decompress

compress.lzma_decompress(data: string) -> !string

decompresses lzma data

xz_decompress

compress.xz_decompress(data: string) -> !string

decompresses xz data

zlib_compress

compress.zlib_compress(data: string) -> !string

compresses data using zlib format

zlib_decompress

compress.zlib_decompress(data: string) -> !string

decompresses zlib data

zstd_decompress

compress.zstd_decompress(data: string) -> !string

decompresses zstd data

module csv

encode values as csv and decode csvs back into revo values
3 entries

Opts

(value)

alias for ```revo {?delimiter: string, ?terminator: string, ?quote: string?, ?bom: bool} ```

csv encoding and decoding options

decode

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" } }
  

encode

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" } }
  

module dataframe

dataframe functions
1 entries

select

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

module datetime

you already know what it is (might merge into time, idk)
1 entries

today

datetime.today() -> string

returns current date in UTC using ISO 8601 (YYYY-MM-DD) date format

module ffi

dynamic c calls, posix only
4 entries

errno

ffi.errno() -> number

errno from the last ffi call on this vm

func

ffi.func(lib: any, name: string, ret: atom, args: table) -> any

declare a c function, call the handle: return type + arg types as atoms

load

ffi.load(path: string) -> any

open a shared library, returns a handle

varfunc

ffi.varfunc(lib: any, name: string, ret: atom, fixed: table, total: number) -> any

declare a variadic c function: fixed prefix types + total count

module file

filesystem access & ops
5 entries

close

file.close(self: table) -> !atom

closes a file handle table this is currently a logical close for wrapper handles

read

file.read(self: table) -> !string

reads the full file contents as a string

readdir

file.readdir(self: table) -> !table<{name: string, kind: atom}>

returns table of directory entries for the dir handle's path

stat

file.stat(self: table, follow: bool?) -> !fs.Stat

get file metadata as a table; follow optional, defaults to :true: :false leaves symlinks alone

write

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

module fs

filesystem access & ops
12 entries

Stat

(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

chdir

fs.chdir(path: string) -> !atom

changes cwd to the given path

copy

fs.copy(src: string, dst: string) -> !atom

copies a file to a new path, overwriting the destination

exists?

fs.exists?(path: string) -> bool

does path exist? answers :false when missing, raises on unexpected io errors

glob

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.

mkdir

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

open

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

readdir

fs.readdir(path: string) -> !table<{name: string, kind: atom}>

returns table of directory entries

remove

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

rename

fs.rename(old_path: string, new_path: string) -> !atom

renames a file or directory

stat

fs.stat(path: string, follow: bool?) -> !fs.Stat

get file metadata as a table from a path; follow optional, defaults to :true

touch

fs.touch(path: string) -> !atom

ensures a file exists, creating it empty when missing and leaving existing entries alone

module http

http
2 entries

FetchOpts

(value)

alias for ```revo {?headers: table<string, http.HeaderValue>, ?body: string, ?max_redirects: num} ```

fetch options

fetch

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
  })
  

module iter

lazy iterators: range, mapping, filtering, folding and chaining
19 entries

all?

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)

any?

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)

chunk

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}}

collect

iter.collect(iterable: any) -> table

collects all values from an iterable into a table iter.collect(iterable)

collect_string

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"))

count

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)

drop

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))

each

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))

enumerate

iter.enumerate(collection: any) -> function

returns a lazy iterator of (index, value) pairs iter.collect(iter.enumerate({5, 7})) # {{0, 5}, {1, 7}}

filter

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))

find

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)

flat_map

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}

fold

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)

map

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))

range

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

reduce

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)

sum

iter.sum(collection: any) -> num

sums numeric elements, skipping non-numbers iter.sum({1, 2, "x", 3})

take

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))

zip

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}}

module json

encode values as json and decode json back into revo values
2 entries

decode

json.decode(source: string) -> !any

decodes json string into revo value

encode

json.encode(value: any, ?pretty: bool) -> !string

encodes value as json string; enabling `pretty` will emit indented json

module math

numeric math
25 entries

abs

math.abs(x: num) -> num

absolute value

acos

math.acos(x: num) -> num

arc-cosine of x (x in radians)

acosh

math.acosh(x: num) -> num

hyperbolic arc-cosine of x (x in radians)

asin

math.asin(x: num) -> num

arc-sine of x (x in radians)

asinh

math.asinh(x: num) -> num

hyperbolic arc-sine of x (x in radians)

atan

math.atan(x: num) -> num

arc-tangent of x (x in radians)

atan2

math.atan2(y: num, x: num) -> num

arc-tangent of y and x (y and x in radians)

atanh

math.atanh(x: num) -> num

hyperbolic arc-tangent of x (x in radians)

ceil

math.ceil(x: num) -> num

ceiling of x

close?

math.close?(x: num, y: num, places: num) -> bool

test whether two values are close within the given number of decimal places

cos

math.cos(x: num) -> num

cosine of x (x in radians)

cosh

math.cosh(x: num) -> num

hyperbolic cosine of x (x in radians)

exp

math.exp(x: num) -> num

e raised to x

floor

math.floor(x: num) -> num

floor of x

hypot

math.hypot(x: num, y: num) -> num

hypotenuse of sides x and y

log

math.log(x: num) -> num

natural logarithm, panics if x <= 0

max

math.max(first: num, args: num...) -> num

max of all arguments, at least one required

min

math.min(first: num, args: num...) -> num

min of all arguments, at least one required

pow

math.pow(base: num, exponent: num) -> num

base raised to exponent

sign

math.sign(value: num) -> num

sign of value (-1, 0, 1)

sin

math.sin(x: num) -> num

sine of x (x in radians)

sinh

math.sinh(x: num) -> num

hyperbolic sine of x (x in radians)

sqrt

math.sqrt(x: num) -> num

square root, errors if x is negative

tan

math.tan(x: num) -> num

tangent of x (x in radians)

tanh

math.tanh(x: num) -> num

hyperbolic tangent of x (x in radians)

module net

tcp sockets: connect, listen, accept, send and receive
2 entries

connect

net.connect(host: string, port: num) -> !table

connects to a remote host and port, returns a socket handle

listen

net.listen(port: num, ?backlog: num...) -> !table

listens for incoming connections on the given port, returns server socket

module number

global number helpers, calllable as `1337:nan?` and `number.nan?(1337)`
8 entries

__call

number.__call(value: string) -> number

metatable key: __call

converts value to number: number("12") => 12

abs

number.abs(self: number) -> number

absolute value

ceil

number.ceil(self: number) -> number

smallest integer >= self

finite?

number.finite?(self: number) -> bool

checks if number is finite

floor

number.floor(self: number) -> number

largest integer <= self

inf?

number.inf?(self: number) -> bool

checks if number is infinite

nan?

number.nan?(self: number) -> bool

checks if number is NaN

round

number.round(self: number) -> number

rounds to nearest integer

module os

1 entries

InputOpts

(value)

alias for ```revo {?delimiter: string | :nil | :eof} ```

read input options

module re

regular expressions!
6 entries

__call

re.__call(pattern: string) -> table

metatable key: __call

compile a regex pattern into a reusable handle

compile

re.compile(pattern: string) -> table

compile a regex pattern into a reusable handle

find

re.find(regex: table | string, haystack: string) -> string?

return first match or nil; pass a string for one-shot compile

find_all

re.find_all(regex: table | string, haystack: string) -> function

return an iterator over all matches; pass a string for one-shot compile

free

re.free(regex: table) -> :nil

free a compiled regex handle

is_match

re.is_match(regex: table | string, haystack: string) -> bool

test if regex matches anywhere in haystack; pass a string for one-shot compile

module revo

the revo metaprogramming lib
5 entries

compile

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

dofile

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

eval

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

threads

revo.threads() -> num

worker thread count (see --threads)

version

revo.version() -> string

version of your revo installation, like "revo v1.2.3"

module rng

pseudo-random numbers with a settable seed
6 entries

choice

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.)

rand

rng.rand(upper_bound: num) -> num

Returns a random integer in the range [0, upper_bound]

rand_float

rng.rand_float() -> num

Returns a random float in the range [0, 1]

range

rng.range(lower_bound: num, upper_bound: num) -> num

Returns a random integer in the range [lower_bound, upper_bound]

revert_seed

rng.revert_seed()

Reverts seed back to using the current time at the time of generation.

set_seed

rng.set_seed(seed: num)

Statically sets the seed used for generation of pseudo-random numbers.

module socket

tcp sockets: connect, listen, accept, send and receive
5 entries

RecvOpts

(value)

alias for ```revo {?mode: :read_some | :read_all | :read_line, ?max_bytes: num, ?delimiter: string} ```

recv options

accept

socket.accept(self: table) -> !table

accepts an incoming client connection on a server socket

close

socket.close(self: table) -> !atom

closes the socket

recv

socket.recv(self: table, opts: socket.RecvOpts) -> !string

receives data according to opts

send

socket.send(self: table, data: string) -> !num

sends data over the socket, returns number of bytes sent

module stats

statistics functions
20 entries

correlation

stats.correlation(input1: table<num>, input2: table<num>) -> num

correlation coefficient of the input data

covariance

stats.covariance(input1: table<num>, input2: table<num>) -> num

population covariance of the input data

frequencies

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

geomean

stats.geomean(input: table<num>) -> num

calculates the geometric mean of an array of numbers

intercept

stats.intercept(input1: table<num>, input2: table<num>) -> num

intercept of the regression of the input data

kurtosis

stats.kurtosis(input: table<num>) -> num

population kurtosis of the input data

mean

stats.mean(input: table<num>) -> num

calculates the arithmetic mean of an array of numbers

median

stats.median(input: table<num>) -> num

middle value of input data

mode

stats.mode(input: table<any>) -> any

most frequent occuring value of input data

regression

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

sample_covariance

stats.sample_covariance(input1: table<num>, input2: table<num>) -> num

sample covariance of the input data

sample_kurtosis

stats.sample_kurtosis(input: table<num>) -> num

sample kurtosis of the input data

sample_skewness

stats.sample_skewness(input: table<num>) -> num

sample skewness of the input data

sample_stdev

stats.sample_stdev(input: table<num>) -> num

sample standard deviation of the input data

sample_variance

stats.sample_variance(input: table<num>) -> num

sample variance of the input data

skewness

stats.skewness(input: table<num>) -> num

population skewness of the input data

slope

stats.slope(input1: table<num>, input2: table<num>) -> num

slope of the regression of the input data

statistics

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

stdev

stats.stdev(input: table<num>) -> num

population standard deviation of the input data

variance

stats.variance(input: table<num>) -> num

population variance of the input data

module string

global string helpers, calllable as `"hello world":split(" ")` and `string.split("hello world", " ")`
26 entries

__call

string.__call(value: any) -> string

metatable key: __call

converts value to string: string(x)

alnum?

string.alnum?(self: string) -> bool

checks if all characters in the string are alphanumeric

alpha?

string.alpha?(self: string) -> bool

checks if all characters in the string are alphabetic

ascii

string.ascii(self: string) -> num

returns ASCII code of first character

"a":ascii() => 97

concat

string.concat(self: string, other: string) -> string

concatenates two strings

contains?

string.contains?(self: string, substr: string) -> bool

checks if string contains substring

ends_with?

string.ends_with?(self: string, suffix: string) -> bool

checks if string ends with suffix

index_of

string.index_of(self: string, substr: string) -> num?

ret 0-based index of substring or nil

join

string.join(table: table<string>, sep: string) -> string

joins table elements into string with separator

len

string.len(self: string) -> num

returns length of string

lower

string.lower(self: string) -> string

converts string to lowercase

lower?

string.lower?(self: string) -> bool

checks if all characters in the string are lower case

of_ascii

string.of_ascii(code: num) -> string

creates string from ASCII code(s)

of_ascii(97) => "a"

punct?

string.punct?(self: string) -> bool

checks if all characters in the string are punctuation

repeat

string.repeat(self: string, n: num) -> string

repeats string n times

replace

string.replace(self: string, old: string, new: string) -> string

replaces all occurrences of old with new

reverse

string.reverse(self: string) -> string

reverses the string

split

string.split(self: string, delim: string) -> table<string>

splits string by delimiter into table

starts_with?

string.starts_with?(self: string, prefix: string) -> bool

checks if string starts with prefix

sub

string.sub(self: string, start: num, length: num) -> string

extracts substring from start with given length

table

string.table(self: string) -> table<string>

converts string to table of characters

"asdf":table() => {"a", "s", "d", "f"}

trim

string.trim(self: string) -> string

trims whitespace from both ends

upper

string.upper(self: string) -> string

converts string to uppercase

upper?

string.upper?(self: string) -> bool

checks if all characters in the string are upper case

whitespace?

string.whitespace?(self: string) -> bool

checks if all characters in the string are whitespace

with

string.with(self: string, idx: num, char: string | num) -> string

replaces character at index with given char or byte index is 0-based

module table

global table helpers, calllable as `{1, 2}:at(0)` and `table.at({1, 2}, 0)`
36 entries

alen

table.alen(self: table) -> num

returns length of table array part only

at

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

at?

table.at?(self: table, index: num) -> bool

whether a 0-based index holds an array element, metatable-ignoring

contains?

table.contains?(self: table, value: any) -> bool

checks if table contains value

copy

table.copy<T>(self: table<T>) -> table<T>

creates shallow copy of table

count_of

table.count_of(self: {}, search_val: any) -> num

returns the number of times a specified value appears in a table's array part

deep_copy

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)

empty?

table.empty?(self: table) -> bool

reports whether the table holds no entries at all

flatten

table.flatten(self: table<any>) -> table<any>

flattens nested tables into single array (non-table elements pass through)

get_meta

table.get_meta(self: table) -> table | :undef

returns metatable of value or :undef

index_of

table.index_of(self: {}, value: any) -> num?

returns 0-based index of value in the array part, or nil if not found

insert

table.insert<T>(self: table<T>, pos: num, value: T) -> :ok

inserts value at position, shifting elements right

join

table.join(self: table, delim: string) -> string

joins array elements with delimiter

key

table.key<V>(self: table<V>, key: any) -> V | :undef

gets map value, metatable-ignoring returns :undef if key missing

key?

table.key?(self: table, key: any) -> bool

whether a key exists, metatable-ignoring

keys

table.keys<K, V>(self: table<K, V>) -> table<K>

returns all keys as table (array indices + hash keys)

klen

table.klen(self: table) -> num

returns length of table keyed entries only

last

table.last(self: table) -> table

the array part's last element

len

table.len(self: table) -> num

returns total length of table (array part + keyed entries)

merge

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

pop

table.pop<T>(self: table<T>) -> T | :undef

removes and returns the last array element, or :undef if empty

push

table.push(self: table, values: any...) -> table

inserts elements as last

rawget

table.rawget(self: table, key: any) -> any | :undef

gets value without metamethods returns :undef if key missing

rawset

table.rawset(self: table, key: any, value: any) -> table

sets value without metamethods

remove

table.remove<T>(self: table<T>, key: any) -> T

removes element at position or key, returns removed value

repeat

table.repeat<T>(self: table<T>, n: num) -> table<T>

repeats table array part n times

reverse

table.reverse<T>(self: table<T>) -> table<T>

reverses table array part in place

set_meta

table.set_meta(self: table, meta: :undef | table) -> table

sets the metatable of the table, `:undef` clears it

slice

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

sort

table.sort<T>(self: table<T>) -> table<T>

sorts table array part in ascending order (numbers < strings)

sort_by

table.sort_by(self: table, fn: function) -> table

sorts table array part using comparison function fn(a, b) -> bool (true if a < b)

unique

table.unique<T>(self: table<T>) -> table<T>

removes duplicate elements

unwrap

table.unwrap<T>(self: {:ok, T} | table) -> T

unwraps result, panics if not :ok

unwrap_err

table.unwrap_err<T>(self: {:err, T} | table) -> T

extracts error from result, panics if not :err

update

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

values

table.values<K, V>(self: table<K, V>) -> table<V>

returns all values as table

module time

clocks
4 entries

monotonic

time.monotonic() -> num

returns monotonic clock in milliseconds

monotonic_ns

time.monotonic_ns() -> num

returns monotonic clock in nanoseconds since the first call

now

time.now() -> num

returns current wall-clock time in milliseconds

now_ns

time.now_ns() -> num

returns current wall-clock time in nanoseconds since the first call

module uri

parse uri strings
3 entries

Uri

(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

decode

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"
  } }
  

encode

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" }