Clojure for Beginners: Clojure def vs let — Values Not Variables
Video: Clojure def vs let — Values Not Variables | Episode 3 by CelesteAI
Take the quiz on the full lesson page
Test what you've read · interactive walkthrough
Clojure def vs let — Values Not Variables
Coming from Python or JavaScript? The word "variable" never appears in Clojure documentation. Clojure binds names to values, and those values never change. This episode shows you why that rewires how you think about code.
Code
;; Episode 3: Values, Not Variables
;; Clojure for Beginners in Neovim
;; def — bind a name to a value at the top level
(def pi 3.14159)
(def radius 5)
;; Use them to compute the area of a circle
(println "Circle area:" (* pi radius radius))
;; let — bind names locally, just for the body of one expression
(let [w 10
h 4]
(println "Rectangle area:" (* w h)))
;; Kebab-case names are idiomatic in Clojure
(def first-name "Ada")
(def last-name "Lovelace")
(println "Name:" (str first-name " " last-name))
;; let can shadow a def — but only inside the let block
(let [pi 3]
(println "Shadow inside:" pi))
(println "pi outside is still:" pi)
Key Points
Watch the video above for a full walkthrough — every keystroke is shown so you can code along.
Student code: GitHub
Ready? Take the quiz on the full lesson page →
Test what you've learned. Watch the lesson and try the interactive quiz on the same page.