Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure Repl - Is there a way to see what variables have been defined (and are thus available) in a REPL session?

Tags:

clojure

If I've been playing around in a clojure REPL (might have been experimenting with (assoc) or (seq) or (reduce) and created some temporary maps for examples), but wanted to print a listing of variables defined in that session, is there a way to do this? Something like (println def) or something?

like image 841
mrjbj Avatar asked Oct 27 '25 10:10

mrjbj


2 Answers

You can use (dir user) if you are in the user namespace. Or any other ns you are interested into. This shows you all the def-ed things. If it's not there (it usually gets useed automatically in the REPL, you can find it in clojure.repl/dir).

like image 79
cfrick Avatar answered Oct 30 '25 14:10

cfrick


ns-interns can get you pretty close I think.

user=> (def x 1)
#'user/x
user=> (def y 2)
#'user/y
user=> (ns-interns *ns*)
{x #'user/x, y #'user/y}
like image 33
Alex Miller Avatar answered Oct 30 '25 14:10

Alex Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!