with-accumulator
macro which sets an environment for easy accumulation. The library provides several built-in accumulators which should cover the most common use-cases but any kind of accumulators can be added because the accumulator back-end is implemented through generic functions.(with-accumulator (NAME OBJECT &key KEYWORD-ARGUMENTS ...)
BODY ...)
Some examples
GENACC> (with-accumulator (collect :list)
(collect 1) (collect 2) (collect 3)
(collect))
(1 2 3)
GENACC> (with-accumulator (collect (list 1 2 3))
(collect 4) (collect 5)
(collect))
(1 2 3 4 5)
GENACC> (with-accumulator (collect :vector)
(collect "first") (collect "second")
(collect))
#("first" "second")
GENACC> (with-accumulator (collect :string)
(collect #\a)
(collect "bcd")
(collect #(#\e #\f))
(collect '(#\g #\h #\i))
(collect))
"abcdefghi"
GENACC> (with-accumulator (summing #'+)
(summing 5) (summing 7) (summing 11)
(summing))
23
GENACC> (with-accumulator (nc #'nconc)
(nc (list 1 2 3))
(nc (list 4 5 6))
(nc (list 7 8 9))
(nc))
(1 2 3 4 5 6 7 8 9)
GENACC> (with-accumulator (early-char (lambda (a b)
(if (char< a b) a b)))
(early-char #\o)
(early-char #\b)
(early-char #\s)
(early-char))
#\b
For more information and examples read the project's README file.
language extension, Public Domain, accumulators