Sorry, I overlooked that you already ruled out all IDeref instances. On Sunday, August 31, 2014 10:21:39 PM UTC-4, Atamert Ölçgen wrote:
> > > On Mon, Sep 1, 2014 at 1:52 AM, <adrian...@mail.yu.edu <javascript:>> > wrote: > >> If you don't want to wrap the object in an atom, you can also reify an >> object that supports IDeref which returns your object. All reified objects >> support IObj out of the box. >> > > As I said earlier: > > ... can't deref it since I can't change the functions that will use it >> later. > > > And again, later: > > I can't really pass a list since the first function is expecting the >> object I am passing, > > > That was why I was asking how to attach metadata. > > > >> >> On Sunday, August 31, 2014 4:55:58 AM UTC-4, Atamert Ölçgen wrote: >> >>> Hi Francis, >>> >>> >>> On Sat, Aug 30, 2014 at 1:34 PM, Francis Avila <fran...@gmail.com> >>> wrote: >>> >>>> 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? >>>> >>> >>> It's not an atom-holding object. The only guarantee is that this object >>> extends one (or two) of these protocols: http://clecs.muhuk. >>> com/api/0.2.1/clecs.world.html >>> >>> Other than that, it can be anything. A Java class, or a type or a >>> record... >>> >>> >>> >>>> >>>> >>>> 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} >>>> >>> >>> This is really cool. So I can do (deref (meta-AtomHolder (atom "x") {})) >>> and it would return "x", right? >>> >>> I have actually managed to solve it using vars, had to move things >>> around a bit: https://github.com/muhuk/clecs/blob/master/src/clecs/ >>> world/check.clj#L73 >>> >>> >>> >>>> >>>> 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 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/d/optout. >>>> >>> >>> >>> >>> -- >>> 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 clo...@googlegroups.com >> <javascript:> >> 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 <javascript:> >> 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 <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > 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.