On Apr 30, 1:41 am, Laurent PETIT <[email protected]> wrote:
> Hi,
>
> 2009/4/30 Stuart Sierra <[email protected]>:
>
>
>
> > On Apr 29, 5:58 pm, Stu Hood <[email protected]> wrote:
> >> Instead of attaching the metadata directly to the object, what if the
> >> metadata was stored outside the object, in a global map of {object
> >> metadata,
> >> ...}? In order to handle garbage collection, something similar to Java's
> >> WeakHashMap could be used, with the object itself as the key.
>
> > Interesting idea.
>
> > There might be performance penalities, depending on how often metadata
> > is used. Metadata guarantees atomic updates (alter-meta!) so the
> > WeakHashMap might need to be wrapped in a synchronized map, at a
> > further penalty.
>
> I guess this would not be sufficient: WeakHashMap are not side-effect
> free: they mutate every time one of their key is removed :
> "When a key has been discarded its entry is effectively removed from
> the map, so this class behaves somewhat differently than other Map
> implementations."
>
> , making them improper to be used within STM transactions and such.
>
> Regards,
>
> --
> Laurent
>
>
>
> > I've never needed metadata on non-Clojure types. Do you have a use in
> > mind?
>
> > This could be a library, too, sort of like:
>
> > (defn my-meta [object]
> > (if (instance? clojure.lang.IMeta object)
> > (meta object)
> > (*global-metadata* object)))
>
Metadata for arbitrary objects is not a supportable idea.
First off, there is the fundamental question about whether an object
is truly a value type. If it is not, metadata needs special handling,
essentially being a mutable property of the reference type, a la var/
ref/ns/agent/atom metadata.
If it is a value, then with-meta should work, returning a new value
with the metadata. But doing so for arbitrary value objects would
require a protocol for value cloning.
Then, you need to know which operations require metadata propagation.
That's built into the Clojure data structures but can't be retrofitted
to arbitrary types.
Then there are all the subtleties of metadata being associated with a
value but being recorded as associated with the identity of a value
(e.g. you might have two instances of 42 with different metadata) This
runs completely against the grain of Clojure's value-oriented
programming.
Then you get into the concurrency problems of a centralized metadata
lookup table.
Then you have the GC problems of a huge weak map.
Etc etc. It is simply unworkable IMO.
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---