It would probably help if you said more about the source of this 
atom-holding object. Is it a plain Java class? A deftype/defrecord? Is it 
final?


If you can control the construction of this object and its class is not 
final, you can subclass it and add an IObj implementation. (Note that most, 
maybe all clojure ways of creating classes create final classes, so this 
technique won't work.) The easiest way to subclass is with `proxy`:

(defn meta-AtomHolder [atom-value metadata]
  (proxy [AtomHolderClass clojure.lang.IObj] ;; [superclass, new interfaces]
         [atom-value] ;; constructor args
    (meta [] metadata) ;; subclass method
    (withMeta [newmeta] (meta-AtomHolder newmeta))))
=> (var user/meta-AtomHolder)
(meta-AtomHolder (atom "x") {})
=> #<AtomHolderClass$IObj$40298964 
user.proxy$AtomHolderClass$IObj$40298964@302c28cc>
(meta (meta-AtomHolder (atom "x") {}))
=> {}
(meta (with-meta (meta-AtomHolder (atom "x") {}) {:a 1}))
=> {:a 1}  

If the parent class is final or you can't construct the object yourself, 
you need to delegate method calls from one instance to this object 
instance. I think this is hard-but-not-impossible in java, but I'm not sure.

(Clojurescript has `specify`, which does exactly what you want, but only 
exists because delegation between instances in javascript is trivial.)

On Friday, August 29, 2014 10:16:05 PM UTC-5, Atamert Ölçgen wrote:
>
> Obviously I can't.
>
> But I need to add this capability to an object. During testing I attach 
> meta to this object that contains an atom. Then I pass this object to other 
> functions, known in runtime. I can't use a dynamic var because all this 
> happens within a mock function that may be retried and run in different 
> threads.
>
> I have seen this: 
> http://stackoverflow.com/questions/20724219/simplest-possible-clojure-object-that-can-accept-a-primitive-and-metadata
>  
> but can't deref it since I can't change the functions that will use it 
> later. If I wrap this object I need to be able to delegate all of its 
> functionality to the original object.
>
> I hope this all is not too vague. The code I'm working on is not online 
> yet. But it's for clecs (https://github.com/muhuk/clecs/), I'm adding 
> quickcheck to compare different world implementations.
>
>
> -- 
> Kind Regards,
> Atamert Ölçgen
>
> -+-
> --+
> +++
>
> www.muhuk.com
>  

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to