clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-11-06T10:21:47.070900Z

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?

2020-11-06T10:30:08.071600Z

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

2020-11-06T10:30:37.071800Z

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

thheller 2020-11-06T10:31:19.072Z

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

2020-11-06T10:31:30.072200Z

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

2020-11-06T10:31:58.072400Z

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

2020-11-06T10:32:20.072900Z

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

2020-11-06T10:32:37.073100Z

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

2020-11-06T10:33:20.073300Z

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

2020-11-06T10:35:24.073500Z

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

2020-11-06T10:35:35.073700Z

but we get a ra is not defined error here: https://github.com/reagent-project/reagent/blob/master/src/reagent/core.clj#L10

thheller 2020-11-06T10:36:54.074Z

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

thheller 2020-11-06T10:36:59.074200Z

what does this mean? works just fine for me?

2020-11-06T10:37:50.074600Z

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

2020-11-06T10:38:01.074800Z

after I posted that I discovered that it does work sometimes

thheller 2020-11-06T10:38:55.075Z

ah thought you get it during compile

2020-11-06T10:39:24.075200Z

ah. no, happens when evaluating in selfhost

2020-11-06T10:42:37.075400Z

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

2020-11-06T10:42:51.075800Z

just causing it to recompile, is nondeterministic

2020-11-06T10:55:14.076300Z

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

thheller 2020-11-06T11:00:18.076500Z

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

thheller 2020-11-06T11:00:19.076700Z

dunno why

thheller 2020-11-06T11:10:39.077300Z

ah nevermind it does load everything as expected

thheller 2020-11-06T11:15:40.077500Z

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

thheller 2020-11-06T11:16:04.077700Z

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

thheller 2020-11-06T11:25:39.077900Z

ah I know ...

thheller 2020-11-06T11:26:12.078100Z

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

thheller 2020-11-06T11:27:25.078300Z

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

thheller 2020-11-06T11:30:18.078500Z

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

2020-11-06T11:35:53.078700Z

hm. I don’t recall running into this before

2020-11-06T11:40:05.078900Z

I’ve written this failing test - https://github.com/clojure/clojurescript/compare/master...mhuebert:cljc-macros-require-test

thheller 2020-11-06T11:41:45.079100Z

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

thheller 2020-11-06T11:42:15.079300Z

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

thheller 2020-11-06T11:42:19.079500Z

I don't know why though.

thheller 2020-11-06T11:43:21.079700Z

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

thheller 2020-11-06T11:45:59.079900Z

definitely a head scratcher 😛

2020-11-06T11:48:35.080100Z

indeed