lisp - 定义我自己的读取宏

标签 lisp common-lisp reader-macro

Common Lisp 中有' #' #P 等读取宏,但是如何编写读取宏呢?

像这样:

#T"hello world"
====================>
(gettext "hello world")

最佳答案

您可以使用 set-macro-characterset-dispatch-macro-character ,例如之后:

(set-dispatch-macro-character #\# #\T
  (lambda (s c n)
    `(gettext ,(read s t nil t))))
==> T

你可以使用安装的读取语法

(read-from-string "#T\"this is a test\"")
==> (GETTEXT "this is a test")

关于lisp - 定义我自己的读取宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091701/

相关文章:

clojure - Clojure 中的合并条件参数(CL 样式)

lisp - 将表达式的结果分配给变量

string - 如何在 Common Lisp 中使用填充指针初始化字符串?

python - 解析 HTSQL 时处理语法歧义

lisp - 如何将 cons 插入 lisp 列表中?

list - 将变量值列表添加到 Lisp 列表中

lisp - 检查适当的子集

lisp - Common Lisp 中的反引号 : read and eval

common-lisp - On Lisp 的 #[ read 宏中引用的必要性?