Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (23 sloc) 824 Bytes
(in-package :academy)
(defun ensure-list (element)
(if (listp element)
element
(list element)))
(defun group (list n)
"Group the elements of LIST into lists of N elements each."
(when (zerop n) (error "Groups of zero are no fun."))
(labels ((rec (list acc)
(let ((rest (nthcdr n list)))
(if (consp rest)
(rec rest (cons
(subseq list 0 n)
acc))
(nreverse
(cons list acc))))))
(when list (rec list nil))))
(defun slurp-file (filename)
"Load then entire file of FILENAME into a string."
(with-open-file (stream filename :direction :input :if-does-not-exist :error)
(let ((seq (make-string (file-length stream))))
(read-sequence seq stream)
seq)))