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 at
https://github.com/clojure/clojure/blob/1f11ca3ef9cd0585abfbe4a9e7609be8b255123f/src/clj/clojure/pprint/pretty_writer.clj#L371

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