--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
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 clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Oh wow! I shouldn't have turned my computer off yesterday evening!!! there were many suggestions to try out... :)
Ok let's see...I've got a record with meta-data let's call it FOO and its instance MFOO:
user=> (defrecord FOO [a b c])
user.FOO
user=> (def MFOO (with-meta (FOO. 1 2 3) {:x false :y true}))
#'user/MFOO
Now I want to serialise it but keep the meta-data when reading it back in. pint-dup seems like my only option as it preserves metadata. As you say though, there is no dispatch for '=' so it seems like I'm stuck with standard java serialisation. Even i I convert it to a map with metadata the same thing will happen (#=)...
Is there no way to keep the metadata?
many many thanks :)
On Aug 22, 2013 6:25 AM, "Jim" <jimpi...@gmail.com> wrote:
> this is funny! I thought about this approach but I originally considered it to be a clever hack rather than the official way to do this...
If you need some data persisted or sent over the wire, then it should probably be considered part of a value, and maybe metadata isn't an appropriate place to store it. It could go into the record, as in Meikel's workaround, or in some wrapper structure, if you need to maintain the behavior that records with distinct metadata can compare =. (Or you could embed the data in the record but `#(dissoc % :data-fka-meta)` only when you want to compare while disregarding that data.)
On Aug 22, 2013 2:19 PM, "Softaddicts" <lprefo...@softaddicts.ca> wrote:
>
>
>
>
> > Jim,
> > > This is indeed a hack and not a best practice, maybe you're not using the > right tool for your problem...
> > > - If you want to exchange data (think values), you should not be in need of > keeping types and meta data
>
> Metadata is part of the Clojure environment and part of the value domain it handles.
> Why should it not be transmitted along with the value ?
> If the receiver is not written in Clojure it may be questionable an probably not
> very useful to transmit it but otherwise ?
I don't think anyone suggested the type of a record should not be part of its edn representation. Here we're talking about arbitrary metadata. While it is "part of the Clojure environment," the way in which it's "part of the value domain it handles" is... subtle.
"An important thing to understand about metadata is that it is not considered to be part of the value of an object. As such, metadata does not impact equality (or hash codes). Two objects that differ only in metadata are equal."
http://clojure.org/metadata
This is indeed a hack and not a best practice
Metadata is part of the Clojure environment and part of the value domain it handles.
Why should it not be transmitted along with the value ?
If the receiver is not written in Clojure it may be questionable an probably not
very useful to transmit it but otherwise ?
> when you exchange data in json, for example, you're not providing object > class in the stream
What's an array then in Json ? Somehow it has to end up in a concrete type.
If both ends are written in Clojure, why not convey the type ? What harm can it do ?
Records are essentially immutable maps. I would carry the type of record as
metadata and let the other end decide to instantiate it or not under the given
record type. This is a personal choice based on the context (same app at both
ends or maybe not, ...).
Again if the receiver is not written in Clojure obviously it does not make sense but if read the OP post correctly, it's not the case.
> > - If you just want serialization to reload hot data or use some kind of RPC > mechanism over the wire, than I think edn is not the right tool.
>
Uh ? "hot data" ? Here we exchange thousands of messages per hour using
Edn. We care little that the data is cold, medium or hot. It simply works..
Configuration data, live data,..
We added a few extensions to support some objects as is but very little.