I am refreshing my memory on how self-host macros work… is it supposed to be acceptable to have a x.cljs
file that :require-macros
a x.cljc
file, or does one have to put everything into a single cljc
file?
context is that i am looking for the least-invasive way to get reagent’s macros to work in self-host
since they are part of the public api, it’s not an option to move them to other macro-specific namespaces
should be fine to have them separate. even .clj
should be fine as long as it doesn't do anything java specific?
eg. reagent.core/with-let
and reagent.ratom/with-let
should both remain in the same ‘place’ api-wise
i thought so, i’ve just been running into super weirdness with my latest attempts
The comment there is not exactly accurate as I’ve found its nondeterministic
compiling/recompiling I get different results, macros are not always resolved when I expect them to be
so i was wondering if the cljs & cljc passes could be clobbering each other somehow, or the compiler state for the namespaces is being corrupted
reagent’s macros currently do not work on selfhost, for reasons I don’t understand. I also thought that .clj
namespaces should be ok as long as they don’t do interop
but we get a ra is not defined
error here: https://github.com/reagent-project/reagent/blob/master/src/reagent/core.clj#L10
;; removing this ns causes `m2 is not defined` error
what does this mean? works just fine for me?
also if you comment / uncomment and it reloads a couple of times?
after I posted that I discovered that it does work sometimes
ah thought you get it during compile
ah. no, happens when evaluating in selfhost
recording… it maybe has nothing to do with whether that line is commented
just causing it to recompile, is nondeterministic
there is also this - https://github.com/mhuebert/shadow-bootstrap-example/blob/8ca524a5794ba42f9cbaec71c6121b4db2a4f6c6/src/userland/macros_2.cljc#L2
I was surprised to find that if I would :require-macros
a cljc namespace that does not self-require, I can’t use the macros from within it
it never even attempts to load the macro ns when in self hosted
dunno why
ah nevermind it does load everything as expected
it might be that some of the bootstrap index data does not look exactly like the self-host compiler needs it to look
because its generated by shadow-cljs and some of the ns-related metadata looks different
ah I know ...
the CLJ-side dependencies aren't followed when constructing the bootstrap index and compiling macros
at least thats how I remember it. so everything in the macro ns itself is directly loaded but its dependencies are not.
so macro namespaces themselves are fine but macro namespaces with dependencies don't work
hm. I don’t recall running into this before
I’ve written this failing test - https://github.com/clojure/clojurescript/compare/master...mhuebert:cljc-macros-require-test
(defmacro current-ns-str
"simple macro that returns info only available at compile time"
[]
;; no-op is just to test re-use of macros from other namespaces
`(userland.macros-2/no-op
~(name (.-name *ns*))))
this seems to work. using the fully qualified symbol to the alias doesn't need to be resolved.
I don't know why though.
but I suppose it might just end up calling the no-op as a function which in this case is fine
definitely a head scratcher 😛
indeed