Emacs 对elisp中格式函数的困惑
我希望得到像0 1这样的输出,但下面的代码只打印nil。我使用类型来测试(第一个十六进制),它是整数d应该有用,对吗?如果我使用message,它在Emacs中工作Emacs 对elisp中格式函数的困惑,emacs,lisp,elisp,Emacs,Lisp,Elisp,我希望得到像0 1这样的输出,但下面的代码只打印nil。我使用类型来测试(第一个十六进制),它是整数d应该有用,对吗?如果我使用message,它在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-ema
(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-emacs lisp格式不是通用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)))
1-emacs lisp格式不是通用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)))
谢谢,我误解了CommonLisp的格式函数。0_0@wvxvw
循环
是一个宏,因此您只需要使用(编译时求值’(require'cl))
,并且如果您编译,则没有运行时惩罚。谢谢,我误解了common lisp的格式函数。0_0@wvxvw循环
是一个宏,因此您只需要使用(编译时求值’(require'cl))
,并且编译时不会受到运行时惩罚。