#Introducing Rig

Rig is a programming language built around explicit staging. The same language describes the program that runs and the computations that prepare it: evaluating constants, constructing types, and generating checked expressions.

The aim is a small set of ideas that compose. Compile-time programming should use the functions, values, and control flow already available in ordinary code, with the boundary between stages visible in types.

#Stages in the Type System

A runtime integer has type Int; an integer used during compilation has type Int_1. The compiler executes higher stages first and incorporates their results into the lower-stage program:

(define double:(Fn_1 Int_1 Int_1) double=(fn value:Int_1 do=(add value value)) answer:(Fn Int) answer=(fn do=(inline (const (double 21))))) (provide answer:(Fn Int))

double executes at Stage 1. const produces checked code for its result, and inline inserts that code into the Stage 0 function. Calling the exported answer returns 42.

This is an explicit language operation, not a request that an optimizer might happen to fulfill. Functions and values retain their stages; a lower-stage expression cannot read a higher-stage value without an appropriate bridge.

#Types Are Ordinary Inputs

Types are values too. Int is a Stage 1 value of type Type_1, and a staged function can accept it just like another parameter:

(define make_id:(Fn_1 Type_1 Syntax_1) make_id=(fn T:Type_1 do=(syntax (fn value:T do=value))) identity:(Fn Int Int) identity=(splice (make_id Int))) (provide identity:(Fn Int Int))

The quotation captures the supplied type. splice uses the declared function type to check the generated Syntax and inserts the completed function. That function can run independently of its compile-time environment.

The same approach lets ordinary functions construct Record or Variant types. Generic programming and code generation share the staged value model instead of requiring unrelated type-parameter and macro systems.

Syntax is bound at its definition site. Inserting checked Code does not resolve its names again against the caller's incidental scope. Runtime inputs belong in generated function parameters; available compile-time data can be persisted explicitly.

#Explicit Choices

Ordinary values have fixed-size copy representations. Box and List share storage. Mutable and Block also allow updates through their operations. Function closures have bounded inline captures rather than an automatically allocated environment; quotation environments are a separate, explicitly constructed value.

These choices do not eliminate allocation. They make storage behavior something an API can communicate, and keep larger storage or shared mutable state deliberate.

Compile-time execution can have effects as well. The native CLI defaults to a restrictive compile profile and an ergonomic runtime profile. Profiles govern authority; they do not make time, randomness, or external inputs deterministic. Staging determines evaluation order, not the reproducibility of arbitrary I/O.

#Components as the Boundary

Rig compiles to WebAssembly Components. Source modules use require and provide; named external interfaces use those same forms with resolved WIT contracts. The compiler handles the contract, while a compatible host decides what it can implement and invoke.

A command exports the standard WASI command interface. A library exports its own API. Resources and asynchronous endpoints cross through the Component Model's ownership and task machinery, without turning every Rig function into a separate async function type.

The examples here export library functions. Getting Started supplies a complete command with output, including the example-local helper that calls WASI.

#Try Rig

The playground builds and runs multi-file projects in the browser. Open the examples, inspect their sources, and change them.

The documentation follows the underlying ideas through bindings, types and values, staging, and Component interoperability. Rig is under active development; the guide distinguishes implemented behavior from the intended installation and library experience.

← All posts