groups every n elements together into new sublists. e.g. (group '(1 a 2 b) 2) -> ((1 a) (2 b))
(defun group (source n) "groups every n elements together into new sublists. e.g. (group '(1 a 2 b) 2) -> ((1 a) (2 b))" (when (zerop n) (error "zero length")) (labels ((rec (source acc) (let ((rest (nthcdr n source))) (if (consp rest) (rec rest (cons (subseq source 0 n) acc)) (nreverse (cons source acc)))))) (if source (rec source nil) nil)))Source Context