Clojure def vs let — Values Not Variables | Episode 3

0views
C
CelesteAI
Description
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. We cover def for top-level bindings, let for locals, shadowing, and the kebab-case naming convention. By the end you will write a values.clj file that computes a circle area, a rectangle area, and demonstrates immutability in action. Student code: https://github.com/GoCelesteAI/clojure-for-beginners/tree/main/episode03 Every keystroke is shown on screen with generous pauses so you can follow along at your own pace. What You'll Learn: - def — bind a name to a value at the top level of a namespace - let — bind names locally, just for the body of one expression - Multiple bindings in one let block - Shadowing — how a let can temporarily shadow a def without mutating it - Kebab-case — the idiomatic naming convention in Clojure - Writing values.clj and running it with :!clj -M % Key REPL Demo: (def pi 3.14159) binds pi globally pi returns 3.14159 (* pi radius radius) computes circle area (let [r 5] (* pi r r)) r exists only inside the let (let [w 10 h 4] (* w h)) multiple bindings at once (let [pi 3] (* pi 2)) shadows pi locally, returns 6 pi still 3.14159 — unchanged (def first-name "Ada") kebab-case is idiomatic Timestamps: 0:00 - Intro 0:12 - Preview: def vs let, immutability 0:25 - Start the REPL 0:29 - def — bind pi globally 0:39 - def in a calculation (circle area) 0:50 - let — local bindings 0:57 - Multiple bindings in one let 1:04 - Shadowing — temporary, local only 1:16 - Kebab-case naming 1:28 - Exit the REPL with Ctrl+D 1:33 - Write values.clj in Neovim 4:56 - Run with :!clj -M % 5:00 - Output explained line by line 5:56 - Review the file 6:00 - Recap 6:22 - What's next — Episode 4 Key Takeaways: 1. def binds a name globally. let binds locally, only for the body of one expression. 2. Names are immutable — they never get reassigned. Re-defining creates a new binding, not a mutation. 3. Shadowing inside a let is temporary — the outer value is untouched after the let closes. Series Roadmap: - Episodes 1-6: REPL & first values - Episodes 7-13: Collections & sequences - Episodes 14-19: Functional core - Episodes 20-24: Namespaces, projects, testing - Episodes 25-30: State & concurrency - Episodes 31-35: Data modeling - Episodes 36-38: Macros - Episodes 39-41: Interop, Babashka, uberjars - Episodes 42-45: Capstone — web app deployment Next up — Episode 4: Functions with defn. Taught by CelesteAI. Like & subscribe for more Clojure tutorials!
Back to tutorials

Duration

Added to Codegiz

April 16, 2026

📖 Read the articleOpen in YouTube