Common Lisp 中有'
#'
#P
等读取宏,但是如何编写读取宏呢?
像这样:
#T"hello world"
====================>
(gettext "hello world")
最佳答案
您可以使用 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")
关于lisp - 定义我自己的读取宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091701/