Fennel libraries as single files (2023)

https://news.ycombinator.com/rss Hits: 12
Summary

I’m pleased to announce that most of my libraries for fennel are now shipped as single files! It was a long-standing issue with Fennel for me, as there was no clear way to ship both macros and functions in the same file, but after some experimentation, I figured out a way. After a bit of testing with my new library for asynchronous programming I can say that it works well enough to be used in most other libraries. Although the implementation is a bit rough and manual, that’s what I’ll try to describe here today. But first, let’s talk modules. This will be a long post, so buckle up. Modules in various programming languages I find it fascinating that a lot of languages have some kind of a module system, yet most of them hide it from the user behind some special keywords and don’t allow us to operate on modules as we can do with other objects. Lua is not one of these languages - its module system is ingenious and yet very simple. First, let’s look at some other languages so you can understand what I’m getting at. For example, here’s Elixir, a language I sometimes tinker with. I’m using an interactive elixir shell, but it’ll be the same even if I were to put this module into a file: iex(1)> defmodule Lib do ...(1)> def foo(), do: "foo" ...(1)> def bar(), do: "bar" ...(1)> end {:module, Lib, <<70, 79, 82, 49, 0, 0, 5, 180, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 169, 0, 0, 0, 18, 10, 69, 108, 105, 120, 105, 114, 46, 70, 111, 111, 8, 95, 95, 105, 110, 102, 111, 95, 95, 10, 97, 116, ...>>, {:bar, 0}} iex(2)> Lib Lib iex(3)> Lib.foo() "foo" You can see that after the module was defined, we can see a tuple with some keywords, the module symbol, and other stuff. If we try to examine Lib in the shell it just prints Lib. Yet, we can call the function foo from this module via the dot syntax: Lib.foo() If we try to inspect what Lib actually is, we can see that it has a bunch of information but, at least to me, this tells almost nothing of substance: iex(4)> i Lib Term Lib Data ...

First seen: 2025-08-13 04:56

Last seen: 2025-08-13 17:05