【问题标题】:Define my own read macro定义我自己的读取宏
【发布时间】:2013-02-26 14:32:51
【问题描述】:

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

像这样:

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

【问题讨论】:

    标签: lisp common-lisp reader-macro


    【解决方案1】:

    您可以使用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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多