This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-16
Channels
- # adventofcode (93)
- # beginners (104)
- # boot (1)
- # cider (4)
- # cljsjs (2)
- # clojure (174)
- # clojure-austin (1)
- # clojure-greece (5)
- # clojure-spec (13)
- # clojure-uk (32)
- # clojurescript (15)
- # core-logic (13)
- # cursive (13)
- # data-science (8)
- # datomic (11)
- # duct (1)
- # fulcro (22)
- # instaparse (23)
- # jobs (1)
- # lein-figwheel (5)
- # off-topic (13)
- # onyx (13)
- # parinfer (1)
- # pedestal (19)
- # re-frame (33)
- # specter (26)
- # unrepl (22)
What's the idiomatic way to get all the functions from a namespace? I'm able to do (clojure.repl/dir my.ns)
but if I try to do it for multiple ns's in a for-loop, it somehow just returns nil.
Even (clojure.repl/dir (first [my.ns]))
seems to fail, I tried quoting as well to no avail
@mikko very hacky way to get all symbols from ns is
(keys (get-in @cljs.env/*compiler*
[:cljs.analyzer/namespaces
'some-namespace
:requires]))
@hlolli thanks! I'll try that, albeit hacky 🙂
@mikko the right way to do it is: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer/api.cljc#L172-L183
via cljs.analyzer.api/ns-interns
or cljs.analyzer.api/ns-publics
those are public APIs that are guaranteed not to break
also I think @hlolli meant :defs
, not :requires
@anmonteiro Oh, cool. How does one provide the ns as parameter for that funtion? It seems it expects it as a symbol but if I try in CLJS
dev:lab.core=> (cljs.analyzer.api/ns-publics 'lab.core)
#object[Error Error: No protocol method IDeref.-deref defined for type null: ]
the analyzer API is supposed to be used in Clojure
(e.g. in a macro)
Ah OK! I'll try that then 🙂
Yes, that seems obvious now. This information is not available in the JS runtime so it gets expanded beforehand, right?
Thanks a lot – I can take it from here!