Browse Learn Clojure Foundations as a Java Developer

def vs defn in Clojure

Learn when to use def, defn, let, and fn so namespace Vars, local bindings, and named functions do not feel like Java variable assignment.

In Clojure, def creates a var in the current namespace. A var can hold any value: a number, a map, a function, a Java object, etc.

defn is the idiomatic way to define a named function. Conceptually, it is a def whose value is an fn, with some extra conveniences (name, docstring, arglists).

1(def answer 42)
2(defn add [a b] (+ a b))

Why this matters in practice

  • You will see a lot of “top-level defs” in Clojure namespaces; that is how APIs are defined.
  • At the REPL, redefining vars is normal and is part of the workflow.

Java mental model: vars are closer to namespace-scoped bindings than to class fields. They support interactive development and late binding.

In this section

Revised on Saturday, May 23, 2026