Working with the REPL
Learn how Clojure's REPL changes day-to-day development for Java engineers: evaluate forms, redefine functions, reload namespaces, debug live state, and keep exploratory work reproducible.
For many Java developers, the REPL is the single most valuable reason to learn Clojure. Think of it as a live connection to your running program where you can ask questions, try fixes, and explore data without rebuilding or restarting.
This chapter shows you how to evaluate forms safely, redefine functions, reload namespaces, and keep your working memory close to the code. You will also learn practical habits—like keeping side effects at the edges—so that interactive development stays reliable instead of becoming “state soup.”
If your Java workflow is already strong (tests, debuggers, profilers), the REPL does not replace it. It complements it by making experimentation and feedback dramatically faster.
In this section
-
What the Clojure REPL Is For
Understand the Clojure REPL as a live connection to a running program, not just a faster calculator or an interactive substitute for Java's main method.
-
Evaluating Forms at the REPL
Learn what happens when the REPL reads and evaluates a form, how result values differ from side effects, and how to keep experiments safe and repeatable.
-
Defining and Testing Functions at the REPL
Shape Clojure functions against real inputs at the REPL, then promote the useful code back into source files and automated tests so exploratory work becomes maintainable.
-
REPL-Driven Development
Use the REPL as a deliberate development loop for exploring behavior, integrating with running systems, and restarting safely when state no longer reflects source.
-
Handling Errors and Debugging in the REPL
Use the REPL to inspect exception data, recreate failing contexts, evaluate small fixes, and observe values directly instead of guessing from logs alone.
-
Using the REPL in Editors and IDEs
Choose an editor REPL workflow that fits your habits, then learn the common evaluation, reload, and inspection moves that matter everywhere.
-
Integrating the REPL with Build Tools
Understand how the Clojure CLI, Leiningen, and editor-driven REPLs shape classpaths, middleware, aliases, project startup, and daily feedback loops.
-
Hot Reloading Code
Reload changed namespaces deliberately, understand what state survives a reload, and use refresh tooling only when you know what it will scan and restart.
-
Practical REPL Habits
Keep REPL sessions focused, reproducible, and useful to future maintainers instead of letting private interactive state replace source-controlled examples and tests.
-
REPL vs Java main
Treat the REPL and main-style entry points as complementary tools: one for exploratory access to a live system, the other for external startup and deployment.