Introduction
Janet is a small, portable, dynamically typed programming language inspired by Clojure, Lua, and Python. It is designed for embedding into C/C++ applications, writing build scripts, system automation, and rapid prototyping. The entire runtime compiles to a single C file with no external dependencies.
What Janet Does
- Provides a Lisp-like language with familiar syntax for functional and imperative programming
- Embeds into C/C++ applications as a single-file library with a clean C API
- Includes a built-in module system, package manager (jpm), and PEG-based parser combinator
- Offers fibers and channels for lightweight concurrency without OS threads
- Compiles scripts to bytecode for faster loading and optional ahead-of-time compilation
Architecture Overview
Janet compiles source code into bytecode that runs on a custom register-based virtual machine written in ANSI C. The runtime includes a mark-and-sweep garbage collector, a module loader, and an event loop for asynchronous I/O. The entire core is a single C file (~15K lines) with no dependencies beyond libc, making cross-compilation and embedding straightforward.
Self-Hosting & Configuration
- Install via Homebrew, package managers, or compile from source with
make && sudo make install - Use
jpm(Janet Project Manager) to manage dependencies and build projects - Embed by including
janet.candjanet.hin your C project — no separate library needed - Configure the module search path via
JANET_PATHenvironment variable - Pre-compile scripts to images with
janet -c script.janet script.jimagefor faster startup
Key Features
- Tiny runtime (~300 KB binary) suitable for resource-constrained environments
- PEG module for parsing grammars directly in Janet without external parser generators
- First-class fibers enabling cooperative multitasking and coroutine-based workflows
- Built-in networking, file I/O, and OS interaction for system scripting
- Comprehensive standard library covering data structures, regex, JSON, and more
Comparison with Similar Tools
- Lua — Similar embedding niche; Janet offers richer data structures and a more modern standard library
- Guile/Scheme — More traditional Lisp; Janet is smaller and simpler to embed
- Python — Larger ecosystem; Janet is 100x smaller for embedding use cases
- Fennel — Lisp that transpiles to Lua; Janet has its own VM and does not depend on Lua
FAQ
Q: Is Janet a Lisp? A: Janet is Lisp-inspired with s-expression syntax but adds features from Clojure and Python. It uses brackets for arrays and braces for tables.
Q: How do I add packages?
A: Use jpm install package-name. Packages are listed in the Janet package index.
Q: Can Janet replace Lua for game scripting? A: Yes. Janet's embedding API is similar to Lua's, and several game projects use Janet for scripting.
Q: What platforms does Janet support? A: Janet runs on Linux, macOS, Windows, BSDs, and has been ported to embedded systems and WebAssembly.