Clojure S-Expressions & Syntax — The One Rule You Need | Ep 2
0views
C
CelesteAI
Description
The parentheses scared you off Lisp once. In this episode we master Clojure's syntax in five minutes flat. Clojure has exactly one rule — prefix notation — and once you see it, you can read any Clojure code.
We start in the REPL with the four basic operators, then build up to nested expressions, variable arity, and the mind-bending idea that code is data. By the end you'll write a `syntax.clj` file that demonstrates every concept.
Student code: https://github.com/GoCelesteAI/clojure-for-beginners/tree/main/episode02
Every keystroke is shown on screen with generous pauses so you can follow along at your own pace.
What You'll Learn:
- Prefix notation: function first, arguments after — (+ 1 2 3) instead of 1 + 2 + 3
- Variable arity: why + takes any number of arguments and there's no operator overloading
- Nesting: how inner expressions evaluate inside-out
- "Code is data": how a quoted list has the same shape as code
- Inspecting code with first, count, and other sequence functions
- Writing and running syntax.clj with :!clj -M %
Key REPL Demo:
(+ 1 2 3) returns 6
(- 10 3) returns 7
(* 2 3 4) returns 24
(+ 1 (* 2 3)) returns 7 (inner form first)
(* (+ 1 2) (- 10 4)) returns 18
'(+ 1 2 3) returns the literal list (+ 1 2 3), unevaluated
(first '(+ 1 2 3)) returns + (the operator as a symbol)
(count '(+ 1 2 3)) returns 4
Timestamps:
0:00 - Intro
0:12 - Preview: the one syntactic rule
0:24 - Start the REPL
0:31 - Prefix basics — +, -, *, /
0:46 - Variable arity — any number of args
0:59 - Nesting — inside-out evaluation
1:16 - Code is data — quote, first, count
1:34 - Exit the REPL with Ctrl+D
1:39 - Write syntax.clj in Neovim
3:45 - Run with :!clj -M %
3:47 - Output explained line by line
4:19 - Review the file
4:23 - Recap: prefix, arity, nesting, code is data
4:45 - What's next — Episode 3
Key Takeaways:
1. Prefix notation is the one syntactic rule in Clojure — every expression is (function args...)
2. Core operators are variable-arity — no overloading, no special cases
3. Code is data — a quoted list is literally a list you can inspect and transform
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 3: Values, Not Variables (def & let).
Taught by CelesteAI. Like & subscribe for more Clojure tutorials!