Clojure · v1.1.5
2026-11-23 14:00:34
defn, let, conditionals, sequence functions, threading macrosfn, defn, #(), arities, variadic and keyword argumentsloop and recur; higher-order and anonymous functionsbindingtry is an expression: it returns a valuecatch clauses are tried in order: most specific firstfinally always runs; its value is discardedfn creates a function value; def gives it a namedefn does both, and stores a docstring that doc prints%1, %2, … are the arguments by position; % is the same as %1#(* %1 %2) is (fn [a b] (* a b)) with the names left outArityException& collects the remaining arguments into a sequence, or nil when there are none&:or supplies a default for each keyword not given; the order of pairs does not matter& as keywords: named at the call, defaulted when absentrecur rebinds and jumps: no new frame, but only for self-recursion in tail positiontrampolineloop binds i and acc, and marks a recursion pointrecur jumps back to it with new values for the bindingsrecur gives the resultloop and recur are iteration written as recursion: no mutable variable, no new stack frame.

i and acc; the pass with (zero? i) returns acc.recur: six passes, and the bindings are the only state
recur: one frame, rebound in place.factorial-rec keeps a frame per call, waiting to multiply: (factorial-rec 100000N) throws StackOverflowErrorloop/recur needs a single frame for any nrecur must be in tail position: nothing remains to be done after itloop, or of the functionapply spreads a collection into a function’s argumentssome returns the first logically true result, so it can find as well as testconstantly: a function from a value; complement: the negation of a predicatecomp applies right to left; partial fixes the leading arguments%& names the remaining arguments, or nil when none remain#() cannot nest, and hides parameter names: use fn once a function needs explainingfn around themA symbol is resolved where it is written, searching outward:
let or fn parameter that binds itdefUnable to resolve symbolf’s body names x outside any let, so it always means the var: the caller’s let is not visible to itscale is a free variable of the inner function, which closes over itA closure carries state without a mutable variable.
^:dynamic is resolved when it is used, by searching the run-time call stack
binding of it still in force on this threaddefbinding gives a dynamic var a new value for the extent of its body: every function called from it, at any depth*earmuffs* name a var meant to be reboundtotal takes no rate parameter, and neither does anything that calls ittax reads the rate of the calling context: 13% by default, 5% inside the bindingtaxlet creates a new lexical name, visible only in its own body’s text; tax still reads the varbinding changes the var itself, for everything the body calls^:dynamic can be boundmap is lazy: tax runs when the result is printed, after the binding has endeddoall realises the sequence inside the bindingfuture carries the caller’s bindings into its threadLexical scope is fixed by the program’s text; dynamic scope by the program’s execution.
use pulls names in unqualified; require with :as keeps their origin visible:import; defn- defines a private function(defn print-amounts
[[amount-1 amount-2 & remaining :as all]]
[amount-1 amount-2 remaining all])
(print-amounts [10.95 31.45 22.36 2.95])
;=> [10.95 31.45 (22.36 2.95)
; [10.95 31.45 22.36 2.95]]
(defn print-first-category [[[category amount] & _]]
[category amount])
(print-first-category [[:books 49.95] [:coffee 4.95]])
;=> [:books 49.95]& collects the rest; :as names the whole; _ marks a part not wanted:or supplies a default for an absent key:keys when local names match the keywords; :as names the whole maplet, parameters, doseq, fortry is an expression; catch clauses run most specific firstdefn is def plus fn; #() for short functions& collects the rest; keyword arguments name the optionsloop/recur iterates in one stack frame; recur only in tail positioncomp, partial, complement build functions without fnbinding rebinds a ^:dynamic var for everything it callsrequire with :as keeps a name’s origin visibleState and the Concurrent World — the next unit in this module.