公告
财富商城
积分规则
提问
发文
2020-06-16 03:44发布
放荡不羁爱自由
I would like to define my own reader macro in clojure:
(read-string "ßfoo") => (some_func :foo)
Is it possible?
Currently, Clojure doesn't allow to create user defined reader macros. This might/might not change in the future.
It is possible to create tagged literals by having a reader map in data_readers.clj at the top of your classpath.
data_readers.clj
This must be in data_readers.clj at the top of your classpath (usually src directory).
src
{ß 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.
最多设置5个标签!
Currently, Clojure doesn't allow to create user defined reader macros. This might/might not change in the future.
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 (usuallysrc
directory).This goes into reader-demo.core
Invoking
will return
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.