liveBook · Manning

Binding vector

As explained in Clojure: The Essential Reference

A binding vector is a vector-form binding specification that associates local names with values or iteration parameters.

A binding vector supplies the local name and iteration bound for dotimes. Its two elements define the variable available to the body and the number of repetitions. section 3.4.5

For dotimes, the binding vector must satisfy this contract:

  • Use exactly two elements: a local binding name followed by n. section 3.4.5
  • The local name starts at zero and increments by one on each iteration. section 3.4.5
  • A zero or negative n skips the body; dotimes returns nil. section 3.4.5

Printing the iteration index

(dotimes [i 3] (println i)) ;; 0 ;; 1 ;; 2 ;; nil Here, [i 3] binds i to each index from zero through two. The body performs side effects, while the overall expression returns nil. section 3.4.5

How Clojure: The Essential Reference covers it

How deep it goes
Defines the two-element contract, index progression, skipped execution, and nil return, without general binding-vector internals.
Examples
Demonstrates index printing, performance measurement, and transient-vector construction with dotimes.
What you can do after
Apply it via dotimes to name an iteration index, control repetition, and perform indexed side effects.
How it connects
Connects binding vectors to dotimes, side effects, array access, transient collections, and lazy sequences.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.