【发布时间】:2013-02-26 14:32:51
【问题描述】:
Common Lisp 中有一些读宏,比如'#'#P,但是如何写一个读宏呢?
像这样:
#T"hello world"
====================>
(gettext "hello world")
【问题讨论】:
标签: lisp common-lisp reader-macro
Common Lisp 中有一些读宏,比如'#'#P,但是如何写一个读宏呢?
像这样:
#T"hello world"
====================>
(gettext "hello world")
【问题讨论】:
标签: lisp common-lisp reader-macro
您可以使用set-macro-character 和set-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")
【讨论】: