Emacs tip: add lexical-binding: t to your elisp files. This makes closures easier to reason about and lets the byte compiler find more bugs.
miniblog.
Related Posts
> If you work on PLs long enough, you will develop a finely honed skill at creating bizarre programs like this that are technically valid but likely to trip up an implementation written by someone with a less perverse imagination than you.
I've just added closure support to my toy programming language: https://github.com/Wilfred/garden/commit/d1fb4566a2187dfe98fb1d2278a7a0d2acd8059e
Closures are more fiddly than I expected, but I now have a much better understanding of what downward/upward funargs are :)
(Downward: passing a closure, upward: returning a closure)
Neat elisp feature I learnt today: because closures are just lists, you can manually construct them and call them as functions:
(mapcar '(closure (t) (x) (1+ x)) '(1 2 3)) ;; => '(2 3 4)