⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠐⠢⠒⣲⢄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢠⢒⢰⠄⠀⠀⠀⢀⠌⠀⠀⠀⡌⠄⣀⠂⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡜⢸⠈⠠⡀⠀⢀⠃⠀⠀⠀⠀⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢣⠀⢀⠀⠦⡀⢧⡄⠀⣷⠁⢀⡨⠐⠒⠀⠤⢄⡀⠀⠀⠀
⠀⠀⠀⠀⢀⡀⠀⠣⡉⠢⡀⠑⡄⠃⠐⠠⠰⢁⠤⠤⠤⠀⠀⠀⠈⠢⡀⠀
⠀⠀⢀⠎⠁⠀⠀⠀⠀⠱⠎⠱⠈⢸⡀⢀⠎⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆
⠀⣀⢎⠾⠑⠃⠈⠁⠀⠰⠖⢉⠉⢐⣠⠖⠐⠢⣀⣀⣀⣀⠤⠒⠒⢄⠀⡇
⠸⠁⠀⣀⣀⠀⠀⢀⠤⠒⠋⢁⠔⡌⢘⢄⠀⠀⠙⡄⠀⠀⠀⠀⢗⠃⢃⠇
⠠⣤⣮⠀⠀⠀⡠⠁⠀⡴⠊⠁⠀⡇⠈⠀⠀⠀⠀⢠⠀⠀⠀⠀⠀⠈⠁⠀
⠀⠀⠀⠀⠀⢠⠁⠀⠀⠀⠀⠀⢠⠴⡄⠀⠀⠠⡀⠀⠣⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠸⡀⡎⣴⢒⠊⠉⠀⠀⠀⠑⠢⡀⠑⠄⠀⢱⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠑⠬⠮⠟⠀⠀⠀⠀⠀⠀⠀⠘⠦⠐⠐⠊⠀⠀⠀⠀⠀⠀

revo in 1 minute

more

to get help on any function, just go over to ./std

you can also point :h in the repl at any documented declaration

rεvo > #* just returns 5 *#
     > global hi = fn() 5
hi()/0
rεvo > :h hi
fn hi() -> int
just returns 5
rεvo > :h print
print(args: any...) -> :ok
prints values to stdout with space separator

the fundamental types are:

types

the compiler infers types, tracks them, and uses them to pick fast paths.
they fall back to any when inference fails.

type annotations

bindings and function parameters can carry type annotations:

return types come after ->:

function-typed bindings also validate arguments:

tables can be annotated by shape, extra fields are fine:

array entries are positional, just the type:

type aliases

type creates a local name for a type expression:

type expression syntax:

syntax meaning
int built-in name or alias
int? int | :nil (optional sugar)
int | string union type
{int, string} table with two array entries
fn(int) -> bool function signature
fn(?a: int) -> bool function signature with optional param
table<int> table with value type int
table<string, int> table with key string, value int
{ name: string } table with field name: string (extra fields ok)
{ ?name: string } table where name: string may be absent (name: string? instead means the key is required but may hold :nil)
{ number, number } table with two array entries (extra fields ok)
{ number, name: string } mixed array and named fields
!int :ok(int) | :err(any) (error union sugar)

type names cannot be used as values at runtime:

ambient declarations

declare names something the host provides

you’re gonna need this for calling functions that come from outside of revo

it works like a typed const, the compiler trusts the type and compiles references
to a plain global load, and the value must exist at runtime or you get undefined variable

function ambients declare a signature with no body. calls typecheck against it
and the return type flows into inference:

#* ... *# attaches text for the lsp hover:

declare is top-level only, once per name, order-sensitive like const, and
rejects value rebinding of the name.

union types

unions model tagged values. each variant is either an atom alone or an atom with a payload:

coercion

assigning a value to a typed binding coerces automatically when safe:

type narrowing

type predicates in if conditions narrow the type within the branch:

supported predicates: number?, string?, table?, atom?, function?, opaque?, resource?

runtime type predicates

built-in checks that narrow types at runtime:

typeof(x) returns the runtime type as an atom:

structural types

tables carry fields and closures; structural types describe their shape:

field writes just work:

table methods

methods are closures stored in the table and receive self as the first
argument. method fields go in the type too, so colon calls resolve to
them instead of baselib methods with the same name:

? suffix convention

functions whose name ends with ? must return bool:

opaque

opaque wraps a raw pointer as a value:

opaque values compare by pointer identity and have no destructor; the caller manages the pointer’s lifetime

resource

owned handles from c! same hiding as opaque, plus a per-handle
metatable & a __gc hook. light never finalizes; resource does, once

operators

standard arithmetic and comparison work as you’d expect:

integer division with // floors toward negative infinity, like python. it works on floats too
(x // y is floor(x / y)), returning an int when both operands are integral and a float otherwise
bitwise operators are spelled as words and, like python, reject non-integral operands at runtime:

since numbers are all the same runtime type, “integral” is judged by value: 2 band 3.0 works (3.0 is integral),
but 2 band 3.5 is an error. // 0 is a runtime error

bitwise operators bind tighter than +/- but looser than *//, so 1 + 2 band 3 is 1 + (2 band 3)
rather than (1 + 2) band 3. shl/shr wrap on overflow; shift amounts outside 0..63 are a runtime error

^ is exponentiation, like python’s **. it’s right-associative and binds tighter than multiplication and
unary minus (-2 ^ 2 is -(2 ^ 2) == -4). integral base with non-negative integral exponent stays an
integer (wrapping); anything else gives a float (2 ^ -1 == 0.5):

numbers are plain doubles, so literals may use the full float range (1.5e300 is fine). arithmetic
overflow gives inf (1e308 * 10), which compares and propagates like math says; dividing by zero
is a runtime error, not nan

and/or preserve value semantics rather than collapsing to booleans, which makes them useful
for default values and short-circuit guards:

assignment operators exist and work as you’d expect. since assignment is an expression, it
returns the rhs:

~ concatenates values into strings!!! polymorphic with fast paths for strings and numbers:

custom types can opt in via __tostring:

control flow

if/else

if is an expression and returns the value of whichever branch was taken:

loops

loop creates a loop block. a loop always evaluates to :nil; break exits it, continue skips to the next iteration

BUT you CAN carry a value out of a loop!!!
break out of a labeled loop or do-block with a value:

labeled loops

loops and do-blocks can carry a label (like loop/a, for/a, while/a, do/a). break/a exits the named block with the value you give it; continue/a restarts the named loop. a labeled block only produces a value when it is exited with a labeled break; otherwise it evaluates to :nil:

while and for

match

match arms are expressions. wildcards and guards let you cover complex cases cleanly:

comma arms try each pattern in order, first hit wins:

a miss falls through to :nil, and the type knows it
cover every variant and the :nil is gone:

the checker warns when an arm can’t fire
covered tags first:

same for patterns the subject can’t meet:

pipe operator

pipe passes a value as the first argument to the next expression:

they apply to most of the language, since everything will likely return something useful

pipes pair well with ?, orelse, and match for error handling:

iteration

all collection functions live under the iter module. transforms (iter.map, iter.filter,
iter.take, …) return lazy iterators; call iter.collect (or iter.collect_string,
iter.collect_string) to materialize them into a value. terminal ops (iter.reduce,
iter.each, iter.find, iter.all?, iter.any?, iter.count, iter.sum) run eagerly:

slicing

[start..end] extracts a contiguous portion of a string or table.
[start..step..end] adds a step to skip elements. any bound can be omitted.

errors

revo does not have exceptions and tries to crash only in extreme scenarios

this means, errors are treated as values
if a function may error, it’s likely to return either
{:ok, value}
… or {:err, :ErrorName}

see examples/errors.rv for full examples

propagation: ? and orelse

revo has two operators for error handling: ? for early return and orelse for defaults

the ? operator

? propagates errors up the call stack. if an expression is an error ({:err, ...}), the function returns immediately with that error. otherwise, the value is unwrapped. at toplevel, the error panics instead of returning silently.

the toplevel is implicitly a function, so returning an error from it panics too

test blocks

test "name" do ... end defines a small test body that only runs when you pass --test
it uses the same module scope as the rest of the file, so it can call local helpers directly

if a test body hits ? on an error, it behaves like the rest of the language and panics at top-level

orelse

orelse assigns a default value when an expression is nil, undef, or an error

builtins

revo ships a small set of helpful globals without imports:

len(x) - length of strings, tables:

panic(msg) - crashes with an error message:

number(s) - parse a string into a number, returns {:ok, n} or {:err, :ParseError}

string(x) - convert any value to its string representation

string_of(code) and string_of({codes}) - create a string from ASCII code(s):

string.join(table, sep) - join table elements into a string:

inspect(x) - prints the value and returns it (useful in pipe chains):

assert_eq(a, b) - panics if values differ, returns a on success:

expect(cond) - panics if condition is false, returns :ok on success. commonly used with ? in test blocks:

input() - reads a line from stdin (os-only), returns {:ok, line} or {:err, :EndOfStream} on EOF. use input({delimiter = :eof}) to read all of stdin:

cwd() - current working directory path:

print(...) - prints values to stdout:

typeof(x) - returns the runtime type as an atom (see types)

revo.eval(code) - evaluate a string as revo code at runtime:

fibers and channels

fibers are cooperative (not preemptive). the main fiber runs first and the run queue is FIFO.

spawn takes a function call expression and runs it in a new fiber
, returning a {:fiber, id} handle

join is a builtin that blocks until it’s done and returns the result

channels coordinate fibers. unbuffered channels (chan()) block the sender until a receiver
is ready. buffered channels block only when full:

yield suspends the current fiber and pushes it back to the run queue. sleep(ms) parks it
without blocking other fibers:

baselib modules

revo ships a small set of helpful globals without imports: essentials like print, read, cwd,
and revo.eval, plus a few module-style namespaces

fs - file and directory access:

json - encode and decode json:

math - numeric helpers:

time - wall-clock and monotonic time:

net - tcp sockets:

net.connect is offloaded from the vm thread: a slow or unreachable host won’t freeze
other fibers while the kernel finishes the handshake.

os - system access (read from stdin, etc.)

system - run a subprocess and capture its output:

exit 0 gives {:ok, {stdout, stderr}}; anything else is an error.
non-zero exit carries its code, signal death reports :Signaled:

strings interpolate expressions with #{{}}. normal interpolation uses display formatting;
use :? for debug formatting or :p for pretty formatting:

fmt remains useful for dynamic format strings:

debug_info - inspect the current vm state:

modules

import resolves a string path to a table of public declarations

each candidate dir tries name, name.rv, name/init.rv

ref:fn resolveImportPath(raw_path
ref:NativeResult.other

cached by absolute path + mtime. change the file, re-import reloads
cycles caught via loading_stack before they hang

for nerds

ref:fn moduleStamp
ref:loading_stack

preload
ast walk before expansion extracts macros from imports:

ref:fn preloadImports(vm
ref:fn resolveModuleFile(vm

wrapModule
module_scope = true wraps root ast with exports:

|# source                  |# after wrapModule
|1 pub const x = 1         |1 const @exports = {{}}
|1 pub fn add(a, b) a + b  |2 const x = 1
|3                         |3 @exports[:x] = x
|4                         |4 fn add(a, b) a + b
|5                         |5 @exports[:add] = add
|6                         |6 @exports
ref:fn wrapModule

compiler
import_stmt is a first-class node, not sugar
compiles to: load_global import, const "path", call 1, reg_dupe, bind_local.
const x = import "path" double-binds if names differ.

ref:.import_stmt => |is| {
ref:if (b.value.expr == .import_stmt and b.target.expr == .ident) {

project detection
Project.detect walks ancestors for lib.json/exe.json
sets project_root, appends "paths" to package_path. in script mode,
simple bare names fail unless a package_path template matches

ref:Project.detect
ref:vm.project_root
ref:vm.package_path

module_dir
set to importing file’s dir, restored after
relative paths (./, ../) check it. all bare names skip it

ref:vm.module_dir

runtime
native import() fn at std/root.zig

ref:pub fn import(args
ref:fn runImportedModule(vm

.so/.dylib resolved paths load as C shared libraries via ffi.

doc comments

names and types carry most of the documentation. for the rest there’s
#* ... *#:

multi-line works too:

any declaration can take one - functions, type aliases, plain values:

extract docs with revo doc script.rv:

# docs for script.rv

- add/2
  adds two numbers

the baselib runs on the same comments: src/baselib/base.rv is the single
source of truth behind runtime registration, compile-time typing, and the
ref:std ">generated reference

advanced

comptime

comp evaluates an expression at compile time and replaces it with the constant result in the
bytecode. compile time happens both when executing a script directly and when running
revo compile in.rv out.rvo:

macro

macros are compile-time code transformers. they can rewrite syntax into any
other syntax, letting you extend the language without runtime cost

if a language doesn’t have metaprogramming, the programmer will metaprogram it themselves

they are also how you implement variable-argument functions

ref:pub const Expr

procedural macros (proc!)

proc macros run arbitrary revo code at compile time. they receive an iterator
of ast nodes and return a new ast node:

ref:pub fn parseProc(

the iterator methods:
ref:pub fn MacroIter

the return value is always a table wrapping a single ast node: {node}

ast data format

the ast is encoded as tagged tables – the same format everywhere (proc macros,
quasiquoting, and revo.parse)

they always match up with the Expr struct:

ref:pub const Expr = union(enum)

building nodes manually works directly with the table format:

you can inspect what the iterator receives using iter:peek() and fmt("%?", ...):

the %? format specifier prints the debug representation of any value

quasiquoting (`)

backtick-quoted expressions build ast data at runtime. %name splices in a
variable’s value:

numbers and atoms quote directly:

tables nest:

combined with a proc macro:

gensym

gensym() gives you a unique interned string each call. use it to generate
fresh names that won’t clash with user code:

ref:pub fn gensym(

essential for macro hygiene! create a gensym’d variable inside a quasiquote
to avoid capture:

ref:var gensym_counter

preloaded macros

these live in src/baselib/base.rv and merge into every build.
right now that file declares no macros; baselib tables can add
pub proc macros there (pub proc uri.shout! ...), called qualified

metatables

metatables let you customize table behavior via metamethods. set one with set_meta:

plain table fields always resolve before __index is called. metatable fields (like methods)
resolve before __index too, which is how obj:method() works without any extra magic:

forloops can also iterate over any object that has an __iter metamethod set