Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (23 sloc) 1.178 kB
(in-package :academy)
(defun rotate-rows-to-columns (rows)
(loop for remaining = rows then (mapcar #'cdr remaining)
while (not (every #'null remaining))
collect (mapcar #'car remaining)))
(defun maximize-length (list &key (key #'identity))
(loop for element in list maximizing (length (funcall key element))))
(defun pad-list (list length &optional (pad-element nil))
(loop for el on list
for x from 1
do (when (null (cdr el))
(setf (cdr el) (make-list (- length x) :initial-element pad-element))
(return list))))
(defun print-table (rows &key (gap " ") (align :right))
(loop with control-string =
(format nil
'string "~{~~~D" (ecase align (:right "@") (:left "")) "A~^" gap "~}~%")
(mapcar (lambda (row) (maximize-length row :key #'princ-to-string))
(rotate-rows-to-columns rows)))
for row in (let ((max-row-length (apply #'max (mapcar #'length rows))))
(mapcar (lambda (row) (pad-list row max-row-length "")) rows))
do (apply #'format t control-string row)))
Jump to Line
Something went wrong with that request. Please try again.