This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-04
Channels
- # aleph (23)
- # announcements (1)
- # babashka (21)
- # beginners (70)
- # biff (3)
- # cider (8)
- # clj-kondo (45)
- # clj-yaml (9)
- # clojure (69)
- # clojure-europe (82)
- # clojure-nl (1)
- # clojure-norway (2)
- # clojurescript (34)
- # conjure (19)
- # core-typed (6)
- # cursive (2)
- # events (5)
- # fulcro (55)
- # honeysql (1)
- # integrant (18)
- # jobs (1)
- # lsp (124)
- # malli (10)
- # meander (1)
- # off-topic (26)
- # polylith (8)
- # reagent (7)
- # releases (1)
- # remote-jobs (1)
- # sci (2)
- # shadow-cljs (19)
- # squint (5)
- # vim (17)
- # xtdb (31)
Does anybody know how one can work with namespaces in ClojureScript?
Kinda fuzzy question, I know, but why aren’t there fns like (all-ns)
, (ns-interns)
etc in CLJS when they’re present in CLJ?
I’m toying around with some meta-ish programming and looking for alternatives to ns discovery.
And https://clojurescript.org/about/differences#_vars_and_the_global_environment. Specifically the "intern not implemented - no reified Vars" part.
I’m by no means a compiler designer, but feels to me like it should be possible to hold a global registry of all defined ns/vars/etc that’s available at runtime?
it's totally possible, but optimizing the size of the javascript output is usually much more important than the value from having the global var registry available at runtime
Nope, not at run time. Some things are available at compile time though.
E.g. ns-interns
is a macro in CLJS, so you can use it, but with a statically provided symbol.
depending on your use case, you can work around it by keeping your own registry, using something like https://github.com/babashka/sci, or using self hosted clojurescript
Yeah, due to optimizations, something like my.project.core/some-var
might end up being just Vx
in a scope of some function.
I think this is pretty neat, but that makes it impossible to do in cljs then https://github.com/Looveh/clj-meta-spec
Actually, that should be possible, assuming all information is there at the compile time.
this looks like a linter? it seems like you could do that with clj-kondo
ah, I think you should still be able to do that as a macro. Vars and var metadata is generally available at compile time.
Right, you certainly can. If you want to use it as is you could just write most of your code in CLJC, then you can run the tool in Clojure. I tend to take this approach because running tests is more convenient in Clojure. ¯\(ツ)/¯
How can I find the namespaces and ns-interns during compile time if (all-ns)
etc aren’t available?
ns-interns etc are all available at compile time, it's kind of confusing... but whenever you define a macro, you are writing CLJ code that will run at compile time. So for example you could write a macro that does those things
And all-ns
in CLJS is actually cljs.analyzer.api/all-ns
, and it's slightly different.
Oh I see.
I’m sure there’s all good reasons for these diffs between clj and cljs and I’m glad both dialects exist, but I really find these diffs confusing
Yes, I tried like so:
(defmacro defexport [binding & body]
`(def ~binding (with-meta
(fn [args#]
,,,)
{:export true})))