For Fennel 1.0 we made sure that it was at least possible to use relative requires, but the method for doing it is awkward and difficult to remember.
Would it be possible to make it as simple as this?
(local access (require (relatively :access))) ; becomes "current-module.access"
(import-macros {: reinit} (relatively :access.macros))
I guess the main thing that's missing here is how do you relatively require something that is in the same directory as the current module. Perhaps a second argument to relatively
could indicate that.
From https://github.com/bakpakin/Fennel/pull/423:
(macro rel-path [module from-macro?] `(.. (or (: (or ... "") :match "(.+%.)[^.]+") (if (= ... ,(if from-macro? "init-macros" "init")) "" (.. ... "."))) ,module))
This macro should cover most common cases for relative require from regular modules and macro modules.
This looks good, but it seems to assume that macros always use
init-macros.fnl
which isn't really accurate; the default macro path allows forinit-macros.fnl
orinit.fnl
; the former is only needed when the latter is already being used by a runtime module.
Had to update the macro above because it stopped working:
(macro rel-require [module macro?] `(if (: (or ... "") :match "(.+%.)[^.]+") (require (.. (: (or ... "") :match "(.+%.)[^.]+") ,module)) (= ... ,(if macro? "init-macros" "init")) (require ,module) (require (.. ... "." ,module))))
Without this change it is compiled to IIFE, and not static.
The technique from the above comment is now part of cljlib. I will monitor if it breaks.