Why does Clojure lack user defined reader macros?

旧城冷巷雨未停 提交于 2019-12-05 12:58:10

From the link in matt's comments, to quote the answer by Rich Hickey, the author of Clojure:

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

Speaking straight there are Tagged Literals that allow you to specify what to do with next form. For example, you can add

{to/u clojure.string/upper-case}

to data_readers.clj (see docs) and write something like this:

testapp.core> #to/u "asd"
"ASD"

but it's not so powerful as full support of reader macros, at least because of The data reader function is invoked on the form AFTER it has been read as a normal Clojure data structure by the reader.

I found this old log (don't ask me how) http://clojure-log.n01se.net/date/2008-11-06.html

where there is a discussion with Rich Hickey's thoughts about reader macros.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!