问题描述
在Clojure中遇到此错误时会发生什么情况?
What is happening when I get this error in Clojure?
java.lang.RuntimeException: No reader function for tag db/id
推荐答案
标记文字
此错误消息与Clojure 1.7中引入的功能有关,
。标记文字是扩展
的一种简单方法,它可以在Clojure代码或
数据。
Tagged Literals
This error message is related to a feature introduced in Clojure 1.7,tagged literals. Tagged literals are a simple means for extendingwhat data types can be represented as literals in Clojure code or EDNdata.
Clojure附带了带有两个标记文字的阅读器,它们分别是 #inst
和
#uuid
允许 java.util.Date
和
<$ c $的文字表示c> java.util.UUID 。可以通过在类路径中将
data_readers.clj
文件包括为。
Clojure ships with readers for two tagged literals, #inst
and#uuid
allowing literal representations of java.util.Date
andjava.util.UUID
. Support for more tags can be added by includingdata_readers.clj
files on the classpath as described in thedocumentation.
此错误的一些常见原因:
Some common causes of this error:
- 尝试读取包含
#db / id的Datomic事务数据
文字 - 尝试使用,而不会在:readers
- http://boot-clj.com/ rel = noreferrer>启动任务,这些任务通过传递
* data-readers * 来尝试使用EDN阅读器code>。
- Trying to read Datomic transaction data containing
#db/id
literals - While attempting to use the EDN reader without passing
:readers
- In Boot tasks that try to use the EDN reader by passing
*data-readers*
.
一个常见问题导致此错误的原因是尝试使用
,而未通过:readers
选项。从文档字符串中获取
clojure.edn / read
:
One common cause of this error is trying to use the EDN readerwithout passing the :readers
option. From the doc string forclojure.edn/read
:
:readers - a map of tag symbols to data-reader functions to be
considered before default-data-readers. When not
supplied, only the default-data-readers will be used.
顾名思义, default-data-readers
仅是与Clojure一起提供的数据
个读者的地图。也就是说,它不包括
您正在使用的任何库
的 data_readers.clj
文件中定义的任何读取器(例如Datomic) 。在这种情况下,解决方案是
通过当前加载的数据读取器集,该集合位于var
* data-readers *
中。
As its name implies, default-data-readers
is only the map of datareaders that ship with Clojure itself. That is, it does not includeany readers defined in the data_readers.clj
files of any librariesyou are using (like, say, Datomic). The solution in this case is topass the current set of loaded data readers, found in the var*data-readers*
.
(clojure.edn/read {:readers *data-readers*} <your-read-source>)
甚至更好的是,显式指定要使用的数据读取器
的映射。例如,如果您只想使用
原子数据读取器:
Or, even better, explicitly specify the mapping of the data readersyou want to use. For instance, if you want to be able to use only thedatomic data readers:
(require 'datomic.db
'datomic.function
'datomic.codec)
(edn/read {:readers {'db/id datomic.db/id-literal
'db/fn datomic.function/construct
'base64 datomic.codec/base-64-literal}}
<your-read-source-here>)
当然,由于这些只是我们正在处理的Clojure映射,因此
还可以包含默认数据读取器
通过合并地图:
And of course, since these are just clojure maps we're dealing with,we could also include the default-data-readers
by merging the maps:
(require 'datomic.db
'datomic.function
'datomic.codec)
(edn/read {:readers (merge
default-data-readers
{'db/id datomic.db/id-literal
'db/fn datomic.function/construct
'base64 datomic.codec/base-64-literal})}
<your-read-source-here>)
这篇关于Clojure RuntimeException-标签db / id没有读取器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!