On 19 May 2011 01:55, David Nolen <dnolen.li...@gmail.com> wrote:
> On Tue, May 17, 2011 at 5:52 PM, jlk <lachlan.kana...@gmail.com> wrote:
>>
>> (proxy2  [String]
>> AProtocol?
>> (theseBehaveAsStringsWithThisAdded [] ...)
>>
>> leaving regular Strings unaffected?
>
> The problem is that Java is inherently and early-bound design. It's
> difficult to do efficient composition a la Objective-C where you can just
> forward a method to some other object.
> JDK 7 introduced invokeDynamic which could possibly help w/ this issue but
> sadly there is no hook through the Java language. Perhaps Clojure could
> provide such a hook, but this seems very JDK 7 centric.
> David
>
> --
> 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


Thank you all for the suggestions.

Jonathan pretty much hit the nail on the head with what I was looking
to do - I didn't know you could use the interfaces generated by
protocols in a proxy statement like that, very handy!

String was meant to be an innocuous example, but it saved my next 'why
isn't this working' question :)

A further example of this proxy method not working would be trying to
add methods to a clojure.lang.PersistentVector.  It doesn't seem to
have an <init> ??

Similarly, list is a problem.  The proxy method works when you provide
a value, but PersistentList$EmptyList does not.

It seems to work nicely with clojure.lang.PersistentArrayMap, so this
kind of thing works

(.dosomething (proxy [clojure.lang.PersistentArrayMap user.A] []
(dosomething [] (println (:akey this)))))
-> nil
(.dosomething (proxy [clojure.lang.PersistentArrayMap user.A]
[(into-array Object [:akey :aval])] (dosomething [] (println (:akey
this)))))
-> :aval

ahh corners!


- Lachlan


-- 
J Lachlan Kanaley

M 0413 191 194
E lachlan.kana...@gmail.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

Reply via email to