Substrate, a Lisp for WebAssembly, defines new languages as libraries

Substrate is a programming language that targets WebAssembly. Its site, published by the Substrate Team, describes it as combining the low-level power of C with Racket-style hygienic macros. The compiler is described as self-hosted, fast, and able to run in the browser.

The central idea is what the site calls languages as libraries. Hygienic macros and module hooks let users define new languages and DSLs as importable libraries. The site also mentions flexible, C-like memory management and sandboxing by default.

The landing-page example shows what that means in practice. A library called bend2 gives new syntax for a dependently typed language. The code declares a natural-number type with constructors Z and S, then writes a law that states what a definition must prove. It defines addition by pattern matching, and then states and proves that 0 + b = b for every b, with the proof given as refl. The site presents this as a port of Bend 2, defined inside Substrate rather than built as a separate compiler.

The page makes performance claims. Programs are said to run within about 1.4× of C compiled to Wasm: Substrate scores 1.43×, C at -O2 compiled to Wasm is the 1.00× baseline, and C at -O2 compiled natively is 0.70×. The compiler is said to handle about 46.5k lines per second, against 14.3k for C at -O2. The page does not say whether the 1.43× figure is a mean, a median or a single benchmark.

Other examples on the site are Snake, web-ui, substrate-sqlite and a SQLite explorer dashboard. An in-browser playground compiles and runs programs in a sandboxed worker, with samples named Hello, Variants, Macros, JSON, Memory, Bend 2 and Compile the compiler.

Installation is through npm (npm install -g substrate-lang) and requires Node 22.22.3+ or 24.15+; it can also be built from source on GitHub. The FAQ covers why to choose Substrate over C, Rust or Zig, whether LLMs work well with it, and production readiness. On that last point, the FAQ says APIs may change before 1.0 and that the compiler core is under 12k lines of code. It also sets out the project's outlook on WebAssembly and LLM-era programming.

Key facts

  • Substrate is a Lisp-style language for WebAssembly that combines C-like low-level power with Racket-style hygienic macros.
  • Hygienic macros and module hooks let users define new languages and DSLs as importable libraries; the showcase is a Bend 2 dependently typed language, including a proof that 0 + b = b.
  • Claimed performance: 1.43× the runtime of C -O2 compiled to Wasm (native C -O2 is 0.70×), and a compiler throughput of about 46.5k lines per second versus 14.3k for C -O2.
  • Install with npm install -g substrate-lang (Node 22.22.3+ or 24.15+), build from GitHub, or try the in-browser playground.
  • The FAQ says APIs may change before 1.0; the compiler core is under 12k lines of code.

Why it matters

Most languages that compile to WebAssembly come with a fixed syntax. Substrate's pitch is different: the language is a base for building other languages, which then ship as ordinary importable libraries. The Bend 2 example, a dependently typed language with its own syntax and proofs, is the site's way of showing how far that reaches. The claimed numbers are meant to show the flexibility does not cost much speed: about 1.4× of C compiled to Wasm.

Who it affects

The site is aimed at people who write low-level code for WebAssembly and might otherwise reach for C, Rust or Zig, and at people who like building DSLs with macros in the Lisp and Racket tradition. The FAQ also addresses whether LLMs work well with the language.

How to use it

Install through npm with npm install -g substrate-lang, which needs Node 22.22.3+ or 24.15+, or build from source on GitHub. To try it without installing anything, the site has a playground that compiles and runs programs in a sandboxed worker in the browser. Samples include Hello, Variants, Macros, JSON, Memory, Bend 2 and Compile the compiler. Larger examples listed are Snake, web-ui, substrate-sqlite and a SQLite explorer dashboard.

How solid is it

The performance figures are the project's own claims. The benchmark methodology and workloads are not stated, and it is not stated whether 1.43× is a mean or a median. No author names, release date or version number are given. No independent reviews, adoption figures or production users are mentioned. The FAQ itself says APIs may change before 1.0, and it puts the compiler core at under 12k lines of code.

Risks and caveats

Treat it as pre-1.0 software: the FAQ warns that APIs may change. The speed claims come from the project's own page and cannot be weighed without knowing the benchmarks behind them. The page fragment does not explain how Substrate compiles to WebAssembly or what its memory model is, so claims about C-like memory management and default sandboxing are the site's description only. The Node version requirements are narrow, at 22.22.3+ or 24.15+.

“Hygienic macros and module hooks allow you to use Substrate to define new languages and DSLs as importable libraries.”

— Substrate site (substrate-lang.com)