I sent a message to #clojurescript channel about this, but since the ClojureScript compiler behavior I am seeing might have some subtle explanation, I thought I would send it here, too. The README of this tiny sample project should explain everything: https://github.com/jafingerhut/ouroboros
@andy.fingerhut since .bar
does not have a require for .foo
the compiler can not ensure that .foo
is actually compiled before .bar
. the default compiler logic when then just process your "inputs" (eg. files in the :source-paths
) in an undefined order which ends up compiling .bar
before .foo
and thus complaining about a var it can't find. problem would get even worse with :parallel-build
since with multiple threads it may even sometimes happen to reach (deftype Transient ...)
before its use in .bar
so the error will only appear occasionally
in general it is not safe to access other namespaces without having an explicit :require
for them
So there is an explicit require in namespace foo
of bar
. Shouldn't that mean that bar
must be compiled first always, deterministically?
yes. .bar
will be compiled before .foo
circular stuff isn't allowed
How is what you said different than the order I asked about?
sorry, read that wrong. I didn't look at the ns
of .foo
before 😛
It seems that there is a kind of circularity being allowed here, and warned about, but the compiler goes ahead and generates what appears to be working code, despite that.
yes vars are checked at compile time
but the JS runtime is fine with this at runtime since the "default" behavior is to just warn about missing warns
I haven't examined the JavaScript generated by ClojureScript compiler here, partly since I'm new to JavaScript.
not throw like clojure would
the JS compiler will generated ouroboros.foo.Transient
and JS warns about, but allows, such 'forward references'?
JS doesn't warn no, it is totally fine with that
So I'm guessing that this should not be held up as a good recommended way to write ClojureScript code.
yes. IMHO this should even be a hard error like in Clojure. Not sure why it was made a warning.
Understood. Yeah, hopefully you can understand my confusion at how this was possibly working.
yeah, this works since JS is much more dynamic than the JVM and everything is loaded into the same global scope anyways
so as long as it is loaded into the runtime before it is actually accessed JS will be fine
OK, thanks for the help understanding what is going on. Sounds like a question for #cljs-dev folks for why this is a warning rather than an error.
just doesn't seem very important
one way or the other
heya, would you accept me adding a shadow-cljs section and project template to https://clojurescript.org/guides/project-templates?
I see I can add it as a PR in https://github.com/clojure/clojurescript-site/blob/master/content/guides/project-templates.adoc, but I am not sure if it's welcome to do
added a PR https://github.com/clojure/clojurescript-site/pull/328