Correct, just like closures and reifies.

On Dec 14, 7:33 am, Tom Faulhaber <tomfaulha...@gmail.com> wrote:
> Razvan,
>
> I believe that proxy actually only creates a new class per call site,
> not per instance. However, I can't completely swear to this.
>
> Anyone with more detailed knowledge than I have want to comment?
>
> Assuming I'm right,, you should be fine to have lots of instances.
>
> HTH,
>
> Tom
>
> On Dec 13, 10:47 am, Razvan Rotaru <razvan.rot...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thanks Tom. Using proxy like this could work. But i'm worried about
> > one thing.What happens if I have many instances? With proxy there's a
> > new class with each instance. Could I run out of permgen space?
>
> > On Dec 13, 9:38 am, Tom Faulhaber <tomfaulha...@gmail.com> wrote:
>
> > > Razvan,
>
> > > I think that you can implement your idea of "extending the class with
> > > proxy" in the following way (originally suggested to me by Rich Hickey
> > > & Chris Houser for use with the pretty printer):
>
> > > (let [extra-fields (ref {:field1 extra-value1, :field2 extra-value2}]
> > >   (proxy [Writer IDeref]
> > >     (deref [] extra-fields)
> > >     (write [x] ...)
> > >     other funcs))
>
> > > You don't need to make the extra-values item a ref if you will set the
> > > values immutably at create time.
>
> > > You can see the full example of this 
> > > athttps://github.com/clojure/clojure/blob/1f11ca3ef9cd0585abfbe4a9e7609...
>
> > > The rest of that module is an abomination that was written when I was
> > > still under the influence of CLOS & O-O.
>
> > > Hope that helps,
>
> > > Tom
>
> > > On Dec 12, 5:10 pm, Stephen Compall <stephen.comp...@gmail.com> wrote:
>
> > > > On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote:
> > > > > - function returns a value which is a java instance (not possible to
> > > > > change here, or at least not from what I see - it needs to be a java
> > > > > instance)
> > > > > - i need to be able to call some function which gets some values that
> > > > > are not part of the java class
>
> > > > You should approach such a need with great trepidation:
>
> > > > [org.jboss.netty/netty "3.2.7.Final"]
>
> > > > (import 'org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap)
>
> > > > (def ^:private asides (ConcurrentIdentityWeakKeyHashMap.))
>
> > > > (defn function-with-two-return-values [...]
> > > >   (let [retval ...]
> > > >     (.put asides retval extra-data)
> > > >     retval))
>
> > > > (let [x (function-with-two-return-values ...)]
> > > >   (prn x)
> > > >   (prn (.get asides x)))
>
> > > > --
> > > > Stephen Compall
> > > > ^aCollection allSatisfy: [:each|aCondition]: less is better
-- 
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

Reply via email to