为什么 Clojure 缺少用户定义的 reader 宏?
Why does Clojure lack user defined reader macros?
据我了解,Clojure 不会公开 reader 宏 table 或允许用户定义 reader 宏。
The read table is currently not accessible to user programs.
我只是想知道是否有明确的或明确的声明(大概来自 Rich Hickey)说明将它们排除在 Clojure 之外的理由。
请注意,我 不是 询问 Clojure 缺少用户定义的 reader 宏是好事还是坏事。只是想知道为什么。
坦率地说,Tagged Literals
允许您指定如何处理下一个表单。例如,您可以添加
{to/u clojure.string/upper-case}
到data_readers.clj
(见文档)并写下这样的东西:
testapp.core> #to/u "asd"
"ASD"
但它没有完全支持 reader 宏那么强大,至少是因为
The data reader function is invoked on the form AFTER it has been read as a normal Clojure data structure by the reader
.
我找到了这个旧日志(别问我怎么找到的)
http://clojure-log.n01se.net/date/2008-11-06.html
其中讨论了 Rich Hickey 关于 reader 宏的想法。
来自matt的评论link,引用Clojure作者Rich Hickey的回答:
I am unconvinced that reader macros are needed in Clojure at this
time. They greatly reduce the readability of code that uses them (by
people who otherwise know Clojure), encourage incompatible custom mini-
languages and dialects (vs namespace-partitioned macros), and
complicate loading and evaluation.
To the extent I'm willing to accommodate common needs different from
my own (e.g. regexes), I think many things that would otherwise have
forced people to reader macros may end up in Clojure, where everyone
can benefit from a common approach.
Clojure is arguably a very simple language, and in that simplicity
lies a different kind of power.
I'm going to pass on pursuing this for now,
Rich
据我了解,Clojure 不会公开 reader 宏 table 或允许用户定义 reader 宏。
The read table is currently not accessible to user programs.
我只是想知道是否有明确的或明确的声明(大概来自 Rich Hickey)说明将它们排除在 Clojure 之外的理由。
请注意,我 不是 询问 Clojure 缺少用户定义的 reader 宏是好事还是坏事。只是想知道为什么。
坦率地说,Tagged Literals
允许您指定如何处理下一个表单。例如,您可以添加
{to/u clojure.string/upper-case}
到data_readers.clj
(见文档)并写下这样的东西:
testapp.core> #to/u "asd"
"ASD"
但它没有完全支持 reader 宏那么强大,至少是因为
The data reader function is invoked on the form AFTER it has been read as a normal Clojure data structure by the reader
.
我找到了这个旧日志(别问我怎么找到的) http://clojure-log.n01se.net/date/2008-11-06.html
其中讨论了 Rich Hickey 关于 reader 宏的想法。
来自matt的评论link,引用Clojure作者Rich Hickey的回答:
I am unconvinced that reader macros are needed in Clojure at this time. They greatly reduce the readability of code that uses them (by people who otherwise know Clojure), encourage incompatible custom mini- languages and dialects (vs namespace-partitioned macros), and complicate loading and evaluation.
To the extent I'm willing to accommodate common needs different from my own (e.g. regexes), I think many things that would otherwise have forced people to reader macros may end up in Clojure, where everyone can benefit from a common approach.
Clojure is arguably a very simple language, and in that simplicity lies a different kind of power.
I'm going to pass on pursuing this for now,
Rich