This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-25
Channels
- # announcements (66)
- # aws (1)
- # beginners (60)
- # boot (6)
- # calva (80)
- # cider (3)
- # clj-kondo (14)
- # cljdoc (4)
- # cljs-dev (27)
- # clojure (65)
- # clojure-dev (24)
- # clojure-europe (13)
- # clojure-gamedev (3)
- # clojure-italy (3)
- # clojure-nl (21)
- # clojure-uk (35)
- # clojurescript (98)
- # cursive (25)
- # data-science (3)
- # datomic (10)
- # dirac (16)
- # duct (2)
- # events (2)
- # fulcro (39)
- # jobs-discuss (1)
- # malli (2)
- # other-languages (1)
- # pedestal (26)
- # re-frame (61)
- # reagent (1)
- # reitit (7)
- # shadow-cljs (230)
- # specter (1)
- # tools-deps (29)
- # vim (1)
- # yada (4)
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?
How is what you said different than the order I asked about?
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.
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.
and JS warns about, but allows, such 'forward references'?
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.
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