Simplified Common Lisp reference
reduce
Symbol class: Sequences (Lists, Strings) and Arrays
Syntax:
Symbol type: function
reducefnseqinitial-value(keyword)key(keyword)from-end(keyword)start(keyword)end(keyword) => an object
Argument description:
fn a two argument function
seq a sequence
initial-value an object
key function for extracting values from sequence
from-end direction flag, default is NIL
start bounding index
end bounding index

REDUCE applies function fn to its previous result and next element. The result is what fn returned in last call. For the first call fn is called with either initial-value and first element or first two elements. See also MAPCAR, MAPCAN, MAP.

(reduce #'list '(1 2 3 4)) => (((1 2) 3) 4)
(reduce #'list '(1 2 3 4) :initial-value 0) => ((((0 1) 2) 3) 4)
(reduce #'list '(1 2 3 4) :initial-value 0 :from-end t) => (1 (2 (3 (4 0))))
(reduce #'list '(1 2 3 4) :from-end t) => (1 (2 (3 4)))
(reduce (lambda (x y) (+ (* x 10) y)) '(1 2 3 4)) => 1234
(reduce #'+ '(1 2 3 4)) => 10
(reduce #'* '(1 2 3 4) :initial-value 1) => 24
Function indexFull documentation for reduce (HyperSpec)