@mfikes re ns-resolve
: as far as I can tell, it does not handle resolving vars from namespaces which have not been loaded. Trying to eval
a (require ...)
before the actual eval
(which resolves the symbol) does not always work, as in some cases the analyzer complains that the require
isn't at top level. Would you say it's safe wrap it with (binding [cljs.analyzer/*allow-ns* true] ...)
? At first glance it seems to work ..
Hmm. I don’t have a strong opinion other than it should strive to mimic Clojure as closely as possible
I'm not trying to modify ns-resolve
Ahh. Right. Interesting that you can’t eval a require… you could drop to using cljs.js
directly from self hosted to cause a require to occur, I suspect
yeah, it's strange, if I have say (def x (somehow-resolve 'foo.bar/y))
, then the analyzer (`parse`) sees a 'def
form, disallows 'ns*
forms, and then throws at the 'ns*
form
and yes, currently I use cljs.js
directly
Are you attempting to write a function that will potentially load a namespace as a side effect?
yes, would that be advised against?
it would happen at compile time, if that makes a difference
or maybe it makes it worse 🙂
I suppose if your code isn’t meant to be portable, it doesn’t really matter (in other words, you wouldn’t expect this code to work in regular JVM ClojureScript)
I mean it to be portable, and it seems to be working
Oh. Well, in that case, consider that the ClojureScript compiler loads all namespaces up front as it processes requires. It also looks at the beginning of the file in order to properly figure out a topological sort (especially important if compiling in parallel)
I'm not sure if that affects me, since this is a compile time construct
so I'm in clojure land
Ahh OK
with JVM cljs
anyway, thanks for the directions! I'll do some testing, see how it works out.
👍