Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Clojure lack user defined reader macros?

As I understand it Clojure does not expose the reader macro table or allow user defined reader macros.

From http://clojure.org/reader:

The read table is currently not accessible to user programs.

I'm just wondering if there is a definitive or explicit statement (presumably from Rich Hickey) stating the rationale for leaving them out of Clojure.

Note I'm not asking if it is a good or bad thing that Clojure lacks user defined reader macros. Just wondering why.

like image 786
Paul Avatar asked Sep 08 '15 08:09

Paul


2 Answers

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

like image 82
Erik Kaplun Avatar answered Nov 11 '22 07:11

Erik Kaplun


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.

like image 4
JustAnotherCurious Avatar answered Nov 11 '22 08:11

JustAnotherCurious