Discussion of the Fennel programming language for contributors and users
Sorry I'm not a seasoned Lua programmer and I just tried Fennel and I have to say: I love it! I can finally try to rewrite my Hammerspoon config using Lisp. One thing though annoying me a bit - it is idiomatic in Lua to have camelCased names for functions and vars, in lisp - is to kebabify them. So I'm wondering if there is a way to refer to third party Lua functions using kebab/lisp syntax and somehow force Fennel to correct them into using camelCase. e.g.: instead of `(hs.console.clearConsole)` I would write `(hs.console.clear-console)` https://www.hammerspoon.org/docs/hs.console.html and fennel would compile it into `hs.console.clearConsole()`. Is something like that possible?
Ag Ibragimov <email@example.com> writes: > So I'm wondering if there is a way to refer to third party Lua > functions using kebab/lisp syntax and somehow force Fennel to correct > them into using camelCase. > > Is something like that possible? Sure--there's two ways you could do this. First, you could have a code-rewriting macro which checks for any references to a specified global such as `hs` and performs a rewrite on any direct field references to make them camelCased. This would have no runtime overhead, but it would miss non-direct references such as `(. hs :console :clearConsole)` or any iterator use. The other way (which has nothing to do with Fennel but can be done in pure Lua) would be to use a `__index` metamethod on the tables in question; when a value is not found it could try looking again with the camelCased version instead. However, one of the tenets of Fennel is to keep things simple and try to make the code as close to the equivalent Lua as possible. The more clever tricks you add to let you write code that diverges, the more places there are for bugs to hide. In practice most Fennel code just sticks with camelCase for Lua APIs. In some sense this can be advantageous; it makes it so you can see at a glance whether you're calling code implemented in Fennel or code coming from Lua. My advice would be to stick with the camelCase for a while and come back to it once you've got a little more experience. -Phil