定义我自己的读取宏

Mik*_*one 5 lisp common-lisp reader-macro

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

像这样:

#T"hello world"
====================>
(gettext "hello world")
Run Code Online (Sandbox Code Playgroud)

650*_*502 5

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

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

您可以使用已安装的读取语法

(read-from-string "#T\"this is a test\"")
==> (GETTEXT "this is a test")
Run Code Online (Sandbox Code Playgroud)