I want to add meta-data to different items in a map, but I get an error in Clojure if I rry this with:
{:a
(with-meta
1
{:some-meta-tag "some-meta开发者_运维知识库-data-value"}
)
}
: Is this possible?
I could be wrong, but think you can't attach metadata to a number:
user=> (with-meta 1 {:meta-tag "foo"})
java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IObj
From the docs
"Symbols and collections support metadata, a map of data about the symbol or collection."
This seemed to work:
user=> {:a (with-meta 'foo {:meta-tag "foo"})}
{:a foo}
And
user=> (meta (:a {:a (with-meta 'foo {:meta-tag "foo"})}))
{:meta-tag "foo"}
精彩评论