It occurred to me that the game I was playing shunting initargs off into a
"raw" key of one name or another before converting them into a map might
more comprehensibly be done by treating the raw values (and other
attributes I use to manage these beasts) as metadata. But I need to update
the metadata during the life of my creation. So...
I found alter-meta!, and it seems perfect. Working from one of the doc
examples:
> (def ^{:version 1} doc2 "This is text")
> (alter-meta! #'doc2 #(assoc-in % [:version] 17))
> (meta #'doc2)
;; => {:version 17}
>
Great! But this more realistic example throws an inscrutable error:
(let [x (with-meta {:a 42}
> {:raw 17})]
> (alter-meta! x #(update-in % [:raw] inc))
> (meta x))
Fine. The doc clearly advertises "Atomically sets the metadata for a
namespace/var/ref/agent/atom"
OK, I am working with refs, let's do it!:
(let [x (with-meta (ref {:a 42})
> {:raw 17})]
> (alter-meta! x #(update-in % [:raw] inc))
> (meta x))
Nope. IRef cannot be cast to IObj. ...google...google... Hunh? The :meta
option on ref?
[1] Why the special mechanism?
Well, when in Rome...:
(let [x (ref {:a 42}
> :meta {:m 17})]
> (alter-meta! x #(assoc-in % [:m] 64))
> (meta x))
> ;; => {:m 64}
Booyow!
The bad news is that the metadata is about the map, not the ref. The two
are meant to be inseparable (so no worries about copying the map and losing
the metadata) but what happens in re synchronization?
[2] If I modify the map inside the ref and the ref's metadata at the same
time, will the latter "stick" even if the former gets rolled back?
-hk
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.