Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 26 lines (23 sloc) 0.824 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
(in-package :academy)

(defun ensure-list (element)
  (if (listp 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)
                  (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)
Something went wrong with that request. Please try again.