定义我自己的读取宏

时间:2013-02-26 14:32:52

标签: lisp common-lisp reader-macro

Common Lisp中有一些读取宏,例如' #' #P,但是如何编写读取宏?

像这样:

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

1 个答案:

答案 0 :(得分:5)

您可以使用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")
相关问题