Back

Why Janet? An essay on the small Lisp dialect worth trying
SiTech AI Team2 min read

Why Janet? An essay on the small Lisp dialect worth trying

Programmer Ian Henry explains why the little Lisp dialect Janet became his go-to language for side projects: an eight-instruction core, embeddable C runtime and standalone binaries.

In an essay on his blog, programmer Ian Henry explains why a little Lisp dialect called Janet has been his go-to language for fun side projects for the past couple of years. He liked it enough to write a whole book about it, "Janet for Mortals", published free online.

A small language you can learn in an afternoon

Janet is an imperative language with first-class functions, a single namespace for identifiers and lexical block scoping. Its core is only eight instructions — do, def, var, set, if, while, break and fn — and macros provide higher-level control flow on top. Henry describes the runtime semantics as familiar: "think JavaScript, plus value types, minus all the wats". The entire standard library fits on one page.

From bytecode to standalone binaries

Janet compiles itself to bytecode, writes that bytecode into a C file that also starts up the Janet runtime, and then compiles the result with the system C compiler. The payoff is that programs ship as native executables with nothing to install. A hello-world binary weighs under a megabyte — 784K for Janet 1.27.0 on aarch64 macOS — including the runtime, garbage collector and bytecode compiler, so programs can evaluate Janet code at runtime. The runtime is a small C library that is easy to embed, including in websites.

PEGs, shell scripting and collections

Instead of regular expressions, Janet's text handling is built on parsing expression grammars, which Henry calls simpler, more powerful and more predictable, able to parse HTML, JSON and binary formats with null bytes. A third-party library called sh adds a shell-scripting DSL for pipes and redirects. Collections come in mutable and immutable flavours: immutable values have value semantics, while mutable ones, such as hash tables, compare by identity.

Macros and compile-time values

Writing macros is the feature Henry recommends most, and he says Janet's non-hygienic macros can still be referentially transparent because literal functions can be unquoted. Janet also lets values travel from compile time to run time: compiling a program runs its top-level code and then writes a full snapshot of program state to disk, preserving shared references, generators and closures. The book shows the trick used to generate database bindings from a SQL schema file.

SiTech

SiTech — AI-powered web development

We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.