0

我想得到像0 1这样的输出,但下面的代码只打印nil。我使用 type-of 来测试(第一个十六进制),它是整数。%d 应该可以,对吧?如果我使用消息,它可以在 Emacs 中使用。

(defun draw-board (board)
  (loop for x below 2
        for hex = (aref board x)
        do (format "%d " (first hex))))

(draw-board [(0 2) (1 2) (0 3) (0 2)])
4

1 回答 1

6

1- emacs lisp 格式不是 Common Lisp 格式。注意缺少的论点!

(format "%d" 42) == (cl:format NIL "~D" 42)

2-因此,您的循环所做的唯一事情是:

 - to check that board is a vector with at least two slots. (aref
   signals an error if the index is out of bound).

 - to check that each of those two slots are lists (first signals an
   error when passed a non list).

 - to check that the first element of each each of those two slots
   are numbers. (format signals an error when you pass a non number
   for %d).

就这样。

你从来没有说过你想打印任何东西。

要打印一些东西,你必须把它放在一个缓冲区中,并使用 ps-print-buffer:

(defun draw-board (board)
  (with-temp-buffer
    (loop for x below 2
          for hex = (aref board x)
          do (insert (format "%d " (first hex))))
    (ps-print-buffer)))
于 2012-06-18T03:34:14.657 回答