common-lisp - 是否可以使用宏更改括号的类型?

标签 common-lisp

可以使用宏来更改代码中括号所用的字符吗?例如可以 ()替换为[]

最佳答案

另一个问题中有更多讨论(我认为这可能是重复的),How to define symbols that will work like ( and ) by symbol macro? ,但仍然值得展示这个特定的示例。查看该问题以了解其工作原理。

CL-USER> (set-macro-character #\[
                              (lambda (stream ignore)
                                (declare (ignore ignore))
                                (read-delimited-list #\] stream t)))
T
CL-USER> (set-macro-character #\] (get-macro-character #\)))
T

CL-USER> '[1 2 3]
(1 2 3)

CL-USER> [print 'hello]

HELLO 
;=> HELLO

关于common-lisp - 是否可以使用宏更改括号的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31007846/

相关文章:

common-lisp - Common Lisp Hash-Dot #。阅读器宏

lisp - 循环打印到屏幕

memory-management - Lisp 中的固定大小与可调整大小的向量

lisp - 在 Lisp 中将十进制数转换为八进制数

lisp - 在 Lisp 中打印 defstruct

regex - 为什么将代码作为函数调用比直接在 Clozure Common lisp 中调用要花更长的时间?

common-lisp - 在 Lisp 中从字符串创建变量名

common-lisp - 为什么ql :quickload ignores errors but asdf:load-system is not?

Lisp 代码没有响应

lisp - 根据列表中的对添加两个或多个列表