我想在地图中的不同项中添加元数据,但如果我尝试使用以下代码,则会在Clojure中出现错误:
{:a
(with-meta
1
{:some-meta-tag "some-meta-data-value"}
)
}
这是可能的吗?
我想在地图中的不同项中添加元数据,但如果我尝试使用以下代码,则会在Clojure中出现错误:
{:a
(with-meta
1
{:some-meta-tag "some-meta-data-value"}
)
}
这是可能的吗?
我可能错了,但我认为您无法给数字附加元数据:
user=> (with-meta 1 {:meta-tag "foo"})
java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IObj
来自文档
"符号和集合支持元数据,即有关符号或集合的数据映射。"
这似乎有效:
user=> {:a (with-meta 'foo {:meta-tag "foo"})}
{:a foo}
user=> (meta (:a {:a (with-meta 'foo {:meta-tag "foo"})}))
{:meta-tag "foo"}