Define my own reader macro in clojure

不想你离开。 提交于 2019-12-03 12:47:42

It is possible to create tagged literals by having a reader map in data_readers.clj at the top of your classpath.

This must be in data_readers.clj at the top of your classpath (usually src directory).

{ß reader-demo.core/read-fn}

This goes into reader-demo.core

(defn some-func
  [arg]
  (str "some-func invoked with " arg))

(defn read-fn
  [arg]
  (-> arg
      keyword
      some-func))

Invoking

#ß foo

will return

"some-func invoked with :foo"

This technique is described here: The reader: Tagged literals

Notice that in practice you should namespace your tagged literals as all non-namespaced ones are reserved for Clojure itself.

Currently, Clojure doesn't allow to create user defined reader macros. This might/might not change in the future.

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