Skip to content
HN On Hacker News ↗

Substrate: A Lisp for WebAssembly

▲ 18 points • 5 comments • by unignorant • 6d ago • HN discussion ↗

Pangram verdict · v3.3

We believe that this entire text is human-written.

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 1 of 1
SEGMENTS · AI 0 of 1
WORD COUNT 772
PEAK AI % 0% · §1
Analyzed
Nov 21
backend: pangram/v3.3
Segments scanned
1 windows
avg 772 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 772 words · 1 segments analyzed

Human AI-generated
§1 Human · 0%

Substrate combines the low-level power of C with Racket-style hygienic macros for defining new languages and DSLs. Its compiler is self-hosted, fast, and runs in the browser.counter.subSubstrate(require-unqualified web-ui) (struct state [count i32]) (variant message [increment] [decrement] [reset]) (define (update [s (ptr state)] [m (ptr message)]) (match m [.increment (+= (-> s count) 1)] [.decrement (-= (-> s count) 1)] [.reset (set! (-> s count) 0)])) (component (counter) #:state [s state] #:messages message #:update update (div ([class "counter"]) (button ([on click .decrement]) "-") (output (int (-> s count))) (button ([on click .increment]) "+") (when (!= (-> s count) 0) (button ([class "reset"] [on click .reset]) "reset")))) live0This webpage and the server it runs on are written in Substrate using the framework above. Its source ↗Domain-specific abstractions.Sandboxed security.01Languages as librariesHygienic macros and module hooks allow you to use Substrate to define new languages and DSLs as importable libraries.;; bend2 gives new syntax for a dependently typed language (language bend2) (type N Data [Z] [S [p : N]]) ; natural number ;; a law states what its def must prove (law (add [a : N] [b : N]) N) (def (add a b) (match a [Z b] [(S p) (S (add p b))])) ;; prove that 0 + b = b for every b (law (zero_add [b : N]) (== (add Z b) b N)) (def (zero_add b) refl) 02Flexible memory modelSubstrate has simple C-like memory management. Languages or DSLs can build memory-safe runtimes on top of it.;; a reference-counted Scheme, no tracing GC (language scheme) (define (numbers n) (let loop ([i 0] [acc '()]) (if (= i n) acc (loop (+ i 1) (cons i acc))))) (define (demo) (let* ([before (live-nodes)] [xs (numbers 1000)]) (printf "~a live, " (- (live-nodes) before)) (printf "length ~a, " (length xs)) (printf "~a live\n" (- (live-nodes) before)))) (demo) ;; 1000 live, length 1000, 0 live 03Run code safelySubstrate programs are sandboxed by default and can only access your filesystem and network when and how you allow them. The build system and compiler are also sandboxed.$ substrate run upload.sub fetch: example.com is not granted (--allow-net) 04Fast compilation and executionSubstrate compiles code at ~47k lines per second, and its programs run within about 1.4× of C compiled to Wasm. The compiler builds itself in about a quarter of a second.run time, lower is fasterSubstrate1.43×C -O2 (Wasm)1.00×C -O2 (native)0.70×lines compiled per secondSubstrate46.5kC -O214.3kExamplesScore 0 Best 0Click the board to play.SnakeThe game, written in Substrate.Source on GitHub ↗Bend 2A Substrate port of Bend 2, a dependently typed language.substrate-sqliteSQLite compiled to WebAssembly, with an API in Substrate.Source on GitHub ↗SQLite explorerAn example app that builds a dashboard using substrate-sqlite, illustrating how native code can be linked with Substrate.PlaygroundEdit the program and press Run. It is compiled and run in your browser, in a sandboxed worker beside this page.main.subConsolePress Run, or Ctrl/⌘ + Enter, to compile and run the program.Loading compiler…Ctrl/⌘ + Enter to runInstallInstall Substrate with npm (Wasm runs on V8), or build it from source on GitHub.# requires Node 22.22.3+ or 24.15+ $ npm install -g substrate-langFAQWhy use Substrate over C, Rust, or Zig?These languages are great and compile to WebAssembly, but Wasm is not their primary target. Substrate makes the most sense for domains that need a small and fast Wasm-based toolchain that runs anywhere (including the browser), or powerful compile-time metaprogramming (where macros can build entire languages). Substrate also provides dedicated tooling for deploying and testing code intended to run in the browser.Are LLMs good at using Substrate?Frontier models are very familiar with C semantics and write performant S-expression-style C with few errors. They also understand Racket-style hygienic macros for building languages. One dependently typed language was built with LLMs in more or less a single prompt on Opus 5.5, with further iteration only necessary to improve compile-time performance and efficiency. It helps that the entire Substrate compiler fits into the context window of a large model.Is Substrate ready for production?Substrate is still evolving and its APIs may change before 1.0. The compiler core is small (<12k LOC) and has been extensively tested and dogfooded, but other parts of the language and libraries are less battle-tested.Why a language like Substrate now?Substrate is an answer to a broader question: how will programming change in the era of LLMs? We believe WebAssembly will play an increasingly important role in infrastructure due to the security properties it provides, and one way to see Substrate is as a meta-language that enables rapid exploration of what is possible on WebAssembly. Whether the future of programming becomes more oriented towards high-level verification, or moves closer to the metal, Substrate is a platform that can empower both.