Clojure on Fennel part one: Persistent Data Structures

From hobby hack to a compiler
What started in 2019 as a side project to make Fennel feel a bit more like Clojure has quietly grown teeth. The author built fennel-cljlib — a Fennel library implementing a slice of clojure.core, lazy sequences, immutability, a test harness inspired by clojure.test and kaocha, and even a port of core.async. It has been reported that this work eventually fed into a new project, ClojureFnl: a Clojure-to-Fennel compiler now able to compile many .cljc files, although running the compiled code and standard-library support remain works in progress.
The data-structure problem
Here’s the rub: the early immutability strategy was a pragmatic hack. The itable and immutableredblacktree.lua implementations relied on copy-on-write plus Lua metatables to fake persistence — simple, neat for experiments, but painfully slow for real workloads. Arrays were the worst offenders; copying large sequences on every update is nasty. It has been reported that transients were used to mitigate some costs, but the author concluded that if ClojureFnl was to go further, a proper replacement was necessary.
Hunting for HAMT in Lua
So the search began for real persistent structures: HAMT for hash maps/sets and bit-partitioned tries for vectors — the same primitives Clojure uses. The author surveyed existing Lua efforts (hamt.lua, ltrie, various gists) and found each lacking in one way or another: incomplete features, no transients, no hashset support, or missing custom hashing. Frustration, yes. But also a clear path: borrow the right concepts, rework the bits that don’t fit Lua, and bring real structural sharing to Fennel.
The emotional pivot here is familiar: a beloved experiment meets a hard limit, and that limit forces growth. Will ClojureFnl make Fennel a genuinely viable host for idiomatic Clojure code? It’s early days, but with proper persistent data structures on the table, the project just moved from clever demo to something that could actually matter.
Sources: andreyor.st, Lobsters
Comments