Plaster

text
(defun group (list n) (declare (fixnum n)) (labels ((aux (list n acc) (if (null list) (reverse acc) (aux (nthcdr n list) n (cons (subseq list 0 (min n (length list))) acc))))) (when (> n 0) (aux list n nil)))) (defun partition-by (list &key (f #'identity) (test #'eql)) "Applies F to each car in LIST, splitting it each time F returns a new value based on TEST." (labels ((aux (list test partition acc) (if (null list) (rest (nreverse (if (null partition) acc (cons partition acc)))) (let ((x (first list))) (if (and partition (funcall test (funcall f x) (funcall f (first partition)))) (aux (rest list) test (cons x partition) acc) (aux (rest list) test (list x) (cons partition acc))))))) (aux list test nil nil)))