为什么以下不起作用?
;;;; foo.lisp
(in-package :cl-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(require :cl-interpol))
(cl-interpol:enable-interpol-syntax)
(defun read-and-eval (s)
(eval (read-from-string s)))
(cl-interpol:disable-interpol-syntax)
然后:
LISP> (load (compile-file "foo.lisp"))
=> T
LISP> (read-and-eval
"(let ((a \"foo\")) (princ #?\"${a}\"))")
=> no dispatch function defined for #\?
最佳答案
因为只有一个读者,具有全局状态。您实际上是在打开和关闭宏。在这种情况下,读取器宏仅在您的 read-and-eval
函数在编译时被读取期间启用。
在这种情况下,您需要在 read-and-eval
函数中设置宏,以确保读取器在您需要时处于正确的状态。
关于lisp - 为什么阅读器宏扩展不传播到运行时(读取)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18574918/