Is there some way to see what has already been defined in a clojure session (equivalent to calling ls())? Let's say that I create a few objects:
(def x 1)
(def y 2.2)
(def plus-one (fn [x] (+ x 1)))
Is there a command that can be run to show me that these now exist in the user namespace?
I am doing all the assignments in user namespace.
user> (def *foo 10)
#'user/*foo
;; To see all the public intern mappings in the user namespace.
user> (ns-publics 'user)
{*foo #'user/*foo}
Now let's define a function which is not public
user> (defn- foobar[x]
(println x)
#'user/foobar
When you call ns-publics function. It will not show foobar function in the mappings.
user> (ns-publics 'user)
{*foo #'user/*foo}
To see the intern mappings for the namespace. Use (ns-interns 'YOUR-NAMESPACE)
user> (ns-interns 'user)
{foobar #'user/foobar, *foo #'user/*foo}
Maybe ns-publics
?
Returns a map of the public intern mappings for the namespace.
or ns-map
?
Returns a map of all the mappings for the namespace.
As I understand it, there is no "global environment," there are only namespaces. Of course whichever one you are currently "in" looks like a "global environment" for practical purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With