对elisp中的格式功能感到困惑

时间:2012-06-18 03:08:42

标签: emacs lisp elisp

我想获得 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)])

1 个答案:

答案 0 :(得分: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-打印缓冲液:

(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)))