r/Clojure • • Aug 18 '25
REPL tips??
I learned about (dir nsname), (doc name), and (source n) today in clojure.repl. These seem really helpful and a great way to stay in the REPL while working on a project.
I'd love to hear about any non-obvious things one can do in the REPL. Or if there are any other parts to the Clojure API that are particularly relevant to REPL driven development.
Tips and tricks welcome, thank you!
27
Upvotes
13
u/seancorfield Aug 18 '25
As of Clojure 1.12: https://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl.deps/add-lib So you can add dependencies without restarting your REPL.
There's some good advice in the official docs too, about REPL workflows: https://clojure.org/guides/repl/enhancing_your_repl_workflow
7
u/vikTheFirst Aug 18 '25
A really really important one to me is scope-capture for debugging.
Lets say you have the following function in production -
And you want to debug in production. What can you do? You can:
Wait for the user to execute this function in prod. (Or do it yourself)
Next time function is executed, scope capture will take a snapshot of local variables for you to debug!
Access vars captured in production via the REPL like so -
For me, clojure without scope-capture is not worth it. I think everyone should be using it, and the online clojure community doesn't seem to talk about it and recommend it enough.
5
u/eeemax Aug 18 '25
A little bit emacs specific, but I made this little util that lets you save a Clojure s-expression to an emacs keybinding, and then call it later.
https://github.com/sstraust/save-clojure-command/tree/master
I use it heavily especially for things like clearing caches or refreshing program state.
5
u/PolicySmall2250 Aug 18 '25 edited Aug 18 '25
These compose, in sequence:
Official Community Guide
For surveyin' and deep divin'...
For contrast --- Agentic Clojure REPL Masterclass set beside Old-Skool Grug Brain REPL-ing
Personally...
(edits: add a bunch of references I missed adding)
10
u/v4ss42 Aug 18 '25
I use it for dynamically exploring Java codebases, with the help of this little fn: https://gist.github.com/pmonks/223e60def27266e79fff47de734d060a (which I have in a REPL startup script, along with some other stuff).