Use the REPL as a real development tool: evaluate forms, inspect values, and require the right helpers instead of guessing.
For a Java developer, the REPL is the first tool that changes how you think about programming in Clojure. It is not just a console and it is not just a teaching toy. It is the fastest way to evaluate code, inspect data, and shorten the gap between an idea and a result.
The most important early shift is this:
Do not wait until the whole application is wired up before testing a small idea.
The REPL exists so you can test the small idea immediately.
cljFor interactive work, start the REPL like this:
1clj
The current CLI reference uses clj for REPL examples and clojure for non-REPL commands. The practical reason is simple: clj is the friendlier interactive entry point.
When it starts, you will usually land in the user namespace:
1user=>
That prompt matters. It tells you:
userThe REPL does not care about “lines” the way many shell users expect. It reads forms.
Start with a few simple examples:
1(+ 1 2 3)
2;; => 6
3
4(map inc [1 2 3])
5;; => (2 3 4)
6
7{:user/id 42 :user/status :active}
8;; => {:user/id 42, :user/status :active}
Use the REPL to build the habit of asking:
That is more important than memorizing commands.
The REPL is a great place to define scratch values and tiny functions while you learn or investigate behavior:
1(def tax-rate 0.13)
2
3(defn total-with-tax [subtotal]
4 (+ subtotal (* subtotal tax-rate)))
5
6(total-with-tax 100)
7;; => 113.0
This is especially useful for Java developers because it removes the compile-run-edit cycle for small experiments.
But notice the right lesson:
def freely in the REPL while experimentingdefs as a substitute for real source filesThe REPL is where you discover and verify. The source file is where the lasting program goes.
There is an important nuance here. In a plain clojure.main REPL started by clj, the default user namespace already has several helpful inspection functions referred for you, including:
docfind-docsourceaproposSo in the default user=> prompt, these will usually work immediately:
1(doc map)
2(find-doc "reduce")
3(source merge)
4(apropos "zip")
However, if you switch to a different namespace, do not assume those helpers came with you. In that case, requiring them explicitly is still the reliable move:
1(require '[clojure.repl :refer [doc find-doc source apropos]])
This is a good lesson in Clojure itself:
Clojure keeps a few helpful vars around for recent REPL values:
*1 for the most recent result*2 for the result before that*3 for the one before that*e for the most recent exceptionExample:
1(* 6 7)
2;; => 42
3
4*1
5;; => 42
These are small conveniences, but they become useful once you are exploring or debugging data step by step.
This is a subtle but important shift for Java engineers.
When you define something at the REPL:
1(def config {:port 8080})
you have changed the live REPL session. You have not necessarily changed any source file. That means:
This is powerful, but it also means you need discipline. Use the REPL to explore. Put the result of that exploration back into source files intentionally.
When you start the REPL with clj, you will usually have comfortable command history and line editing. That behavior often comes from the CLI wrapper and terminal setup, not from some mysterious property of the language itself.
So:
clj for interactive workIf you are in an editor-integrated REPL later, it may feel even better. But your terminal REPL should already be enough to learn with.
When you are done with a plain terminal REPL, use:
Ctrl-DThat exits the session. Learn this early so you do not end up killing terminals unnecessarily.
Once the REPL is open:
That is a much healthier loop than piling up ad hoc definitions for half an hour and forgetting which ones matter.
doc are always already loadedThe REPL is most useful when it feeds your source code, not when it replaces it.