Fork me on GitHub
#clojurescript
<
2020-11-06
>
mhuebert10:11:47

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?

mhuebert10:11:08

context is that i am looking for the least-invasive way to get reagent’s macros to work in self-host

mhuebert10:11:37

since they are part of the public api, it’s not an option to move them to other macro-specific namespaces

thheller10:11:19

should be fine to have them separate. even .clj should be fine as long as it doesn't do anything java specific?

mhuebert10:11:30

eg. reagent.core/with-let and reagent.ratom/with-let should both remain in the same ‘place’ api-wise

mhuebert10:11:58

i thought so, i’ve just been running into super weirdness with my latest attempts

mhuebert10:11:20

The comment there is not exactly accurate as I’ve found its nondeterministic

mhuebert10:11:37

compiling/recompiling I get different results, macros are not always resolved when I expect them to be

mhuebert10:11:20

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

mhuebert10:11:24

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

thheller10:11:54

;; removing this ns causes `m2 is not defined` error

thheller10:11:59

what does this mean? works just fine for me?

mhuebert10:11:50

also if you comment / uncomment and it reloads a couple of times?

mhuebert10:11:01

after I posted that I discovered that it does work sometimes

thheller10:11:55

ah thought you get it during compile

mhuebert10:11:24

ah. no, happens when evaluating in selfhost

mhuebert10:11:37

recording… it maybe has nothing to do with whether that line is commented

mhuebert10:11:51

just causing it to recompile, is nondeterministic

mhuebert10:11:14

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

thheller11:11:18

it never even attempts to load the macro ns when in self hosted

thheller11:11:39

ah nevermind it does load everything as expected

thheller11:11:40

it might be that some of the bootstrap index data does not look exactly like the self-host compiler needs it to look

thheller11:11:04

because its generated by shadow-cljs and some of the ns-related metadata looks different

thheller11:11:39

ah I know ...

thheller11:11:12

the CLJ-side dependencies aren't followed when constructing the bootstrap index and compiling macros

thheller11:11:25

at least thats how I remember it. so everything in the macro ns itself is directly loaded but its dependencies are not.

thheller11:11:18

so macro namespaces themselves are fine but macro namespaces with dependencies don't work

mhuebert11:11:53

hm. I don’t recall running into this before

thheller11:11:45

(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*))))

thheller11:11:15

this seems to work. using the fully qualified symbol to the alias doesn't need to be resolved.

thheller11:11:19

I don't know why though.

thheller11:11:21

but I suppose it might just end up calling the no-op as a function which in this case is fine

thheller11:11:59

definitely a head scratcher 😛