Jolt 让 Clojure 直连 C 并编译为独立二进制

原标题:Jolt – Clojure that speaks C
58AI 研判分

Jolt 是一个用 Clojure 编写的自举编译器,将 Clojure 代码分析为宿主中立的 IR 后生成 Scheme,可在 Chez 上原生运行,或经 Gambit 编译为 JavaScript。它提供原生 C FFI、AOT 打包为无 JVM 依赖的独立二进制,并支持基于 OS 线程的真实并发与持久化数据结构。

报道正文

本文目录7 个章节

Why Jolt?

Native C FFI

Bind any C shared library: declare it, wrap functions with defcfn, call them with Clojure values. The db library reaches SQLite and Postgres this way; http-client binds OpenSSL and zlib.

Standalone Binaries

jolt build ahead-of-time compiles a project (runtime, standard library, app, and its deps) into a single self-contained executable, with C dependencies linked statically. No Chez, no JVM, no source needed to run it.

Self-Hosted Compiler

Reads Clojure, analyzes it to a host-neutral IR, emits Scheme, and runs it: on Chez natively, or on Gambit compiled to JavaScript. The compiler is written in Clojure and compiles itself; Chez runs interpreted and compiled code identically, so the REPL and a built binary behave the same.

Real Concurrency

future/promise/agent/pmap run on OS threads over a shared heap, matching JVM semantics. core.async provides channels and go blocks.

Persistent Data Structures

Immutable vectors (32-way tries), cons lists, and HAMT maps/sets with Clojure value semantics. Transients are real mutable scratch collections.

Clojure-Compatible

Lazy/infinite seqs, transducers, destructuring, multimethods, protocols/records, metadata, namespaces, runtime eval, and the full reader.