Browse Learn Clojure Foundations as a Java Developer

Use the REPL in Daily Clojure Workflow

Turn the REPL into a daily engineering workflow: connect the editor, evaluate source-backed forms, capture decisions in tests, and avoid hidden state that teammates cannot reproduce.

REPL-driven development is not “type random code until it works.” A good Clojure workflow uses the REPL for fast feedback while keeping source files, tests, and Git as the durable record.

The Daily Loop

    flowchart LR
	    A["Edit source"] --> B["Evaluate form"]
	    B --> C["Inspect value"]
	    C --> D["Adjust code"]
	    D --> B
	    C --> E["Write or update test"]
	    E --> F["Commit source truth"]

The REPL shortens the loop, but the commit still contains source and tests. That distinction keeps the workflow collaborative.

Connect the Editor

A productive REPL workflow usually evaluates code from the editor, not by pasting large blocks into a terminal.

Editor setup What matters most
Calva in VS Code Jack-in/connect flow, evaluate form, evaluate top-level form, test commands
Cursive in IntelliJ IDEA Correct run configuration, project classpath, evaluate form/file
CIDER in Emacs cider-jack-in, namespace evaluation, test helpers, stack traces
Terminal only Good for learning, but less efficient for source-backed work

Choose the editor that gives you reliable evaluation and clear feedback. Brand loyalty matters less than the ability to evaluate the right form quickly.

Work From Source, Not Terminal History

Prefer this loop:

  1. Write or edit a function in a source file.
  2. Evaluate that function or top-level form.
  3. Call it with sample data.
  4. Move useful sample data into a test.
  5. Commit the source and tests.

Avoid this loop:

  1. Define ten functions directly in the REPL.
  2. Forget which definitions matter.
  3. Restart the REPL and lose the working state.
  4. Reconstruct behavior from history.

The first loop is fast and reviewable. The second loop is private and fragile.

Use Sample Data Deliberately

Keep small domain-shaped examples nearby:

1(def sample-order
2  {:order/id 1001
3   :order/customer {:customer/id 42}
4   :order/lines [{:sku "A1" :qty 2 :price 10}
5                 {:sku "B2" :qty 1 :price 25}]})

Then evaluate source-backed functions:

1(orders.core/order-total sample-order)

When the sample reveals a real requirement, move it into a test fixture or test body.

Convert REPL Wins Into Tests

The REPL answers “does this work right now?” A test answers “will this keep working?”

REPL discovery Durable follow-up
A transform returns the right map Add a unit test
A nil case fails Add an edge-case test
A Java interop call needs a type hint Add source code and a regression test
A dependency API behaves differently than expected Capture the assumption in a wrapper function and test

This is the same engineering discipline Java teams already value; Clojure just gives you a faster way to find the right assertion.

Keep the Running System Honest

Long REPL sessions can drift. Use checkpoints:

Checkpoint Why it helps
Restart after dependency changes Confirms the classpath from a clean process
Run the test suite regularly Catches REPL-only state assumptions
Evaluate from source buffers Keeps files and runtime aligned
Avoid private session-only helpers Keeps teammates able to reproduce work
Document startup commands Makes onboarding and CI consistent

A Practical Java-to-Clojure Rule

If you would normally add a breakpoint, log line, or temporary controller endpoint in Java, first ask whether you can evaluate the relevant function directly in Clojure.

That question pushes you toward:

  • smaller functions
  • explicit data
  • fewer hidden dependencies
  • better tests
  • faster feedback

Key Takeaways

  • A good REPL workflow is source-backed, not history-backed.
  • Evaluate from your editor whenever possible.
  • Use the REPL to discover behavior, then encode durable behavior in tests.
  • Restart when dependency or classpath changes make the live JVM suspect.
  • The REPL complements Git, CI, and tests; it does not replace them.

Quiz: REPL Workflow

### What should happen after a useful REPL discovery? - [x] Move the durable behavior into source and tests. - [ ] Leave it only in terminal history. - [ ] Delete the source file. - [ ] Restart Git. > **Explanation:** The REPL helps discover behavior; source and tests preserve it. ### Why evaluate from the editor instead of pasting large blocks into a terminal? - [x] It keeps runtime evaluation connected to saved source files. - [ ] It prevents all exceptions. - [ ] It removes the need for namespaces. - [ ] It changes Clojure into Java. > **Explanation:** Editor evaluation keeps the source buffer and running process aligned. ### What is the main risk of long REPL sessions? - [x] Hidden live state can drift away from source and tests. - [ ] The JVM stops supporting Clojure. - [ ] Git history disappears automatically. - [ ] All maps become mutable. > **Explanation:** Long sessions can accumulate state that is not reproducible from a clean start.
Revised on Saturday, May 23, 2026