+Calculator and code looks
[lineal.git] / src / math / format.lisp
blob2bd237913ba660c229f3129e09b14b32caf2a2e2
2 (in-package :lineal.math)
4 (defun max-width (&rest nums)
5 (loop :for x :in nums
6 :maximize (length (princ-to-string x))))
8 (defun output-tuple (u &optional (strm t))
9 (format strm "(~{~D~#[~:;, ~]~})" u))
11 (defun output-matrix (mat &optional (strm t))
12 (fresh-line strm)
13 (loop
14 :with widths = (apply #'mapcar #'max-width mat)
15 :for row :in mat :do
16 (princ "[" strm) :do
17 (loop
18 :for width :on widths
19 :and elem :in row
20 :if (cdr width) :do
21 (format strm "~V,@A " (car width) elem)
22 :else :do (format strm "~V,@A]~%" (car width) elem))))