你如何在 lisp 的同一行上打印两个项目?

Jim*_*ion 2 lisp printing format common-lisp

我正在寻找类似的东西:

(printem 1 2)
1 2
Run Code Online (Sandbox Code Playgroud)

我假设您使用格式调用来执行此操作,但示例并不关注这一点。或者你写一个字符串并输出它?但这似乎也不对。

cor*_*ump 5

在 Common Lisp 中,你可以这样写:

(format t "~d ~d~%" 1 2)
Run Code Online (Sandbox Code Playgroud)

请参阅Peter Seibel 的Practical Common Lisp 中的一些 FORMAT Recipes(您可能也对其他章节感兴趣)。


Fra*_*kow 5

您可以简单地构建一个函数,通过format 的迭代构造来打印其所有参数。

(defun printem (&rest args)
  (format t "~{~a~^ ~}" args))
Run Code Online (Sandbox Code Playgroud)

用法:

CL-USER> (printem 1 2 3)
1 2 3
CL-USER> (printem '(1 2 3) '(4 5 6))
(1 2 3) (4 5 6)
Run Code Online (Sandbox Code Playgroud)