Lisp 打印拆分为X列的长列表
有没有办法做到这一点:Lisp 打印拆分为X列的长列表,lisp,format,common-lisp,Lisp,Format,Common Lisp,有没有办法做到这一点: (defvar long-list ((1 1 1 1) (2 2 2 2) (3 3 3 3) (4 4 4 4) (5 5 5 5) (6 6 6 6)) (format t "magic" long-list) 要输出如下内容: (1 1 1 1) (2 2 2 2) (3 3 3 3) (4 4 4 4) (5 5 5 5) (6 6 6 6) 在哪里定义要打印的列数 我知道(format t“~/my function/”long list)
(defvar long-list ((1 1 1 1) (2 2 2 2) (3 3 3 3)
(4 4 4 4) (5 5 5 5) (6 6 6 6))
(format t "magic" long-list)
要输出如下内容:
(1 1 1 1) (2 2 2 2) (3 3 3 3)
(4 4 4 4) (5 5 5 5) (6 6 6 6)
在哪里定义要打印的列数
我知道(format t“~/my function/”long list)
选项,但可能有内置的东西
参考文献对这一特定主题毫无帮助。好的,对不起,我确实找到了它:但在找到它之前,我写了以下内容:
(defun pplist-as-string (stream fmt colon at)
(declare (ignore colon at))
(dolist (i fmt)
(princ i stream)))
(defun ppcolumns (stream fmt colon at cols)
(declare (ignore at colon))
(when (or (not cols) (< cols 1)) (setq cols 1))
(let* ((fmt-length (length fmt))
(column-height (floor fmt-length cols))
(remainder (mod fmt-length cols))
(printed 0)
columns
column-sizes)
(do ((c fmt (cdr c))
(j 0 (1+ j))
(r (if (zerop remainder) 0 1) (if (zerop remainder) 0 1))
(i 0 (1+ i)))
((null c))
(when (or (= j (+ r column-height)) (zerop i))
(setq columns (cons c columns)
column-sizes
(cons
(+ r column-height) column-sizes))
(unless (zerop remainder)
(unless (zerop i) (decf remainder)))
(setq j 0)))
(setq columns (reverse columns)
column-sizes (reverse column-sizes))
(when (/= fmt-length (* column-height cols))
(incf column-height))
(dotimes (i column-height)
(do ((c columns (cdr c))
(size column-sizes (cdr size)))
((or (null c)))
(when (> printed (1- fmt-length))
(return-from ppcolumns))
(when (< 0 (car size))
(pplist-as-string stream (caar c) nil nil)
(when (caar c) (incf printed))
(unless (null c) (princ #\ ))
(rplaca c (cdar c))))
(princ #\newline))))
(默认为字符串(stream fmt colon at)
(声明(忽略冒号)
(多利斯特(i fmt)
(普林斯一流)
(在列中定义PPT列(在列中使用流fmt冒号)
(声明(冒号处忽略))
(当(或(非cols)(打印时(1-fmt长度))
(从PPT栏返回)
(当(<0(车辆尺寸))
(pplist作为字符串流(caar c)nil nil)
(当(caar c)(incf打印)
(除非(空c)(原则)
(rplaca c(cdar c)))
(普林斯·纽兰)
从另一个方向打印。以防你需要它