Get the latest tech news

Implementing dynamic scope for Fennel and Lua


I’m continuing my work on fennel-cljlib, my port of clojure.core and some other core libraries, focusing on porting missing functions and features to it. One such feature, which I sometimes miss in Lua and Fennel, is dynamic binding. The Lua VM doesn’t provide dynamic scoping as a language feature, and Fennel itself doesn’t introduce any concepts like Clojure’s Var.

How, if we were to call it inside of let, the bindings introduced by it won’t affect the function, because both foo and bar are not lexically present here: While this works, I don’t like the idea that we’re actually changing the values instead of shadowing them in the environment, though this is more akin to the original Clojure implementation. Since Lua is single-threaded it should not be problematic, however, I think it can still mess things up if we were to introduce some kind of an asynchronous scheduler, like in my async.fnl library.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of lua

lua

Photo of Fennel

Fennel

Photo of dynamic scope

dynamic scope

Related news:

News photo

Extending Emacs with Fennel (2024)

News photo

Lua beats MicroPython for embedded devs

News photo

Pluto is a unique dialect of Lua with a focus on general-purpose programming