Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
protocols and interfaces
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
drewn  
View profile  
 More options Feb 10, 3:13 am
From: drewn <naylor...@gmail.com>
Date: Fri, 10 Feb 2012 00:13:24 -0800 (PST)
Local: Fri, Feb 10 2012 3:13 am
Subject: protocols and interfaces
I've just started learning protocols, deftype, etc.  The first thing I
did was try to extend a Clojure type (maps) to operate as a
specialized Java Swing interface (AttributeSet), forgetting that
interfaces are not protocols; i.e.

(extend-type clojure.lang.PersistentArrayMap
  javax.swing.text.AttributeSet
  (getAttribute [this k]
                (get this k)))

Is there any way of doing what is intended here: get Clojure maps to
implement Java's AttributeSet?  I've seen Chas Emerick's flowchart,
but I'm still trying to wrap my head around all the choices.

Thanks, Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart Sierra  
View profile  
 More options Feb 10, 9:24 am
From: Stuart Sierra <the.stuart.sie...@gmail.com>
Date: Fri, 10 Feb 2012 06:24:42 -0800 (PST)
Local: Fri, Feb 10 2012 9:24 am
Subject: Re: protocols and interfaces

Nope, can't be done. Java interfaces can't do this.

Java 8 may have "Interface Injection" which will make this possible.
-S


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
drewn  
View profile  
 More options Feb 10, 12:51 pm
From: drewn <naylor...@gmail.com>
Date: Fri, 10 Feb 2012 09:51:39 -0800 (PST)
Local: Fri, Feb 10 2012 12:51 pm
Subject: Re: protocols and interfaces

> Nope, can't be done. Java interfaces can't do this.

I'm glad I asked the question.  Given that it can't be done, any
suggestions for the best way of handling this interop scenario?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Cohen  
View profile  
 More options Feb 10, 1:07 pm
From: Aaron Cohen <aa...@assonance.org>
Date: Fri, 10 Feb 2012 13:07:37 -0500
Local: Fri, Feb 10 2012 1:07 pm
Subject: Re: protocols and interfaces

On Fri, Feb 10, 2012 at 3:13 AM, drewn <naylor...@gmail.com> wrote:
> I've just started learning protocols, deftype, etc.  The first thing I
> did was try to extend a Clojure type (maps) to operate as a
> specialized Java Swing interface (AttributeSet), forgetting that
> interfaces are not protocols; i.e.

> (extend-type clojure.lang.PersistentArrayMap
>  javax.swing.text.AttributeSet
>  (getAttribute [this k]
>                (get this k)))

I think in this case you should be able to use proxy, maybe.

user=> (defn attribute-list [map] (proxy [javax.swing.text.AttributeSet] []
             (getAttribute [k] (get map k))))

user=> (.getAttribute (attribute-list {:a 1 :b 2}) :a)
1


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cedric Greevey  
View profile  
 More options Feb 10, 1:32 pm
From: Cedric Greevey <cgree...@gmail.com>
Date: Fri, 10 Feb 2012 13:32:09 -0500
Local: Fri, Feb 10 2012 1:32 pm
Subject: Re: protocols and interfaces

There's also defrecord:

(defrecord foo [my basis keys]
  the.JavaInterface
  (javaIfaceMethod [this foo] ...))

which will work in the specific case that you want "a Clojure map that
implements a particular Java interface". Records behave partially as
Clojure maps. For more general mixins, proxy, reify, and deftype are
your friends, and even gen-class may be needed in some instances.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
drewn  
View profile  
 More options Feb 10, 3:36 pm
From: drewn <naylor...@gmail.com>
Date: Fri, 10 Feb 2012 12:36:05 -0800 (PST)
Local: Fri, Feb 10 2012 3:36 pm
Subject: Re: protocols and interfaces

> There's also defrecord

I considered using that, but I need to do something more with the
constructor (e.g. convert the map into a Java array for internal
use).  Also, defrecords only takes positional arguments, which will be
hard to use with tens of arguments.  (An alternative is just to pass
in one argument as a map itself, but that seems to defeat the
purpose.)

On Feb 10, 10:32 am, Cedric Greevey <cgree...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »