Fork me on GitHub
#clojurescript
<
2017-12-16
>
Mikko Harju10:12:54

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.

Mikko Harju10:12:28

Even (clojure.repl/dir (first [my.ns])) seems to fail, I tried quoting as well to no avail

hlolli10:12:58

@mikko very hacky way to get all symbols from ns is

(keys (get-in @cljs.env/*compiler*
                                   [:cljs.analyzer/namespaces
                                    'some-namespace
                                    :requires]))

Mikko Harju12:12:41

@hlolli thanks! I'll try that, albeit hacky 🙂

anmonteiro13:12:33

via cljs.analyzer.api/ns-interns or cljs.analyzer.api/ns-publics

anmonteiro13:12:41

those are public APIs that are guaranteed not to break

anmonteiro13:12:08

also I think @hlolli meant :defs, not :requires

Mikko Harju14:12:02

@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: ]

anmonteiro14:12:29

the analyzer API is supposed to be used in Clojure

anmonteiro14:12:03

(e.g. in a macro)

Mikko Harju14:12:13

Ah OK! I'll try that then 🙂

Mikko Harju14:12:58

Yes, that seems obvious now. This information is not available in the JS runtime so it gets expanded beforehand, right?

Mikko Harju14:12:59

Thanks a lot – I can take it from here!