liveBook · Manning

Vector function

As explained in Clojure: The Essential Reference

The Clojure function vector constructs a vector whose elements are its arguments in argument order.

The Clojure function vector creates a persistent vector containing its arguments in the order received. With known elements, the literal [] is shorter and idiomatic; vector is useful when arguments must be collected dynamically. section 12.4

Its contract is straightforward:

  • Accepts zero or more arguments, including nil and other vectors. section 12.4
  • Returns a clojure.lang.PersistentVector; zero arguments produce an empty vector. section 12.4
  • Supports specialized arities from zero through six arguments, then a variadic arity. section 12.4

Literal versus function

(vector :a :b :c) ;; [:a :b :c] [:a :b :c] ;; [:a :b :c] (defn var-args [a b & all] (apply vector a b all)) (var-args :a :b :c) ;; [:a :b :c]

Composing vectors with map

(def m [[1 2 3] [4 5 6] [7 8 9]]) (apply map vector m) ;; ([1 4 7] ;; [2 5 8] ;; [3 6 9])

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, output type, ordering, empty behavior, arities, and specialized performance, without detailing persistent-vector internals.
Examples
Demonstrates equivalent literals, variadic argument collection, palindrome scoring, data comparison, and matrix transposition.
What you can do after
Apply vector to construct ordered persistent vectors from fixed or dynamically supplied values.
How it connects
Connects vector literals, variadic functions, apply, map, and matrix transposition.

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.