gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:35:58 25 4
gpt4 key购买 nike

为什么以下不起作用?

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com