lisp - 为什么阅读器宏扩展不传播到运行时(读取)?

标签 lisp common-lisp reader-macro

为什么以下不起作用?

;;;; 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/

相关文章:

lisp - lisp 中的 CDR 使用

lisp - 为什么python脚本无法从hunchentoot-cgi获取post参数?

common-lisp - 可读与 cl-annot (cl-syntax, jonathan) 和 pythonic-string-reader 冲突

common-lisp - 在读取器宏内部使用时 read 的递归-p 参数

emacs - 参数内的空格字符 (emacs lisp)

lisp - 重复调用格式忽略 ~t 选项

emacs - 如何在 emacs 中查找 CL 函数定义

在 'rest arguments' 读取器宏之后带有 'discard' 宏的 Clojure 函数文字

lisp - GNU CLISP 中的 if 条件

lisp - 如何在拆分字符串后修剪以在 Lisp 中列出