【发布时间】:2016-03-04 23:02:04
【问题描述】:
我想获取一个大列表(想想 emacs 主题中的面孔)并将其分解为单独文件中的较小列表。我遇到的问题是在我读入列表后将(backquote) 应用到列表中。
这是我用来试验解决方案的代码:
(defvar x 23)
(defun read-from-file (file)
(with-temp-buffer
(insert-file-contents file)
(read (current-buffer))))
;;(defun apply-macro (macro arg-list)
;; (eval
;; `(,macro ,@(loop for arg in arg-list
;; collect `(quote ,arg)))))
(defvar parts (mapcar 'read-from-file (directory-files "./parts/" "parts/" "\.part$")))
;;(apply-macro 'backquote parts)
parts
此代码依赖于名为parts/ 的子目录中的“数据”文件。以下是一些示例:
-
parts/one.part
`( ("one" "two" "three") ("ten" ,x "twelve") )
注意:,x在这个。我想在从文件中读取表达式后对其进行评估。 -
parts/two.part
((“四”“五”“六”)(2 4 6)(9 87 6)) -
parts/three.part
((“七”“八”“九”))
读取“部分”文件没有问题。 (defvar parts (mapcar ... ) 表达式有效。
问题在于,一旦我在 parts 变量中获得了列表,我就无法找到评估 ,x 的方法,因为如果整个列表被反引号而不是从文件中读取,就会出现这种情况。
我已经尝试过this question 中建议的a solution。你可以看到我上面的代码中注释掉了apply-macro 函数。当我运行它时,我得到:
Debugger entered--Lisp error: (wrong-number-of-arguments #[(structure) "\301!A\207" [structure backquote-process] 2 1628852] 3)
#[(structure) "\301!A\207" [structure backquote-process] 2 1628852]((quote (\` (("one" "two" "three") ("ten" (\, x) "twelve")))) (quote (("seven" "eight" "nine"))) (quote (("four" "five" "six") (2 4 6) (9 87 6))))
(backquote (quote (\` (("one" "two" "three") ("ten" (\, x) "twelve")))) (quote (("seven" "eight" "nine"))) (quote (("four" "five" "six") (2 4 6) (9 87 6))))
eval((backquote (quote (\` (("one" "two" "three") ("ten" (\, x) "twelve")))) (quote (("seven" "eight" "nine"))) (quote (("four" "five" "six") (2 4 6) (9 87 6)))))
apply-macro(backquote ((\` (("one" "two" "three") ("ten" (\, x) "twelve"))) (("seven" "eight" "nine")) (("four" "five" "six") (2 4 6) (9 87 6))))
eval-region(648 678 t #[257 "\300\242b\210\301\207" [(678) (apply-macro (quote backquote) parts)] 2 "\n\n(fn IGNORE)"]) ; Reading at buffer position 651
eval-defun-2()
#[257 "\211\203
【问题讨论】: