I tried to do it the other way around: find all symbols in a given
namespace and use your protocol? function to find out which of these
is a protocol, and next check with extenders if the class of my object
is included.

However this fails because my code to get all symbols from a
namespace:

(map #(% 0) (ns-publics *ns*))

exactly does that: it gives the symbol names. The protocol? function
doesn't work for a symbol, but needs the actual protocol as parameter.
To make myself hopefully a little bit more clear:

(defprotocol P (bar [x]))
(println (isprotocol? P))

prints true

(map #(isprotocol? (% 0)) (ns-publics *ns*)))

just returns sequence which only contains false values.

Maurits

On Jan 12, 10:48 pm, Bob Hutchison <hutch-li...@recursive.ca> wrote:
> On 2011-01-12, at 8:38 AM, Stuart Sierra wrote:
>
> > One way:
>
> >     (ancestors (type the-object))
>
> > This will include every interface implemented by the object, including 
> > protocols.
>
> This seems to only work if the protocol is mentioned in the defrecord. If 
> it's applied using the extend function it doesn't seem to show the protocol.
>
> The functions bases and supers work similarly.
>
> Unless I'm doing something really stupid, which is a distinct possibility.
>
> Any idea how to tell which of the classes returned by ancestors/bases/supers 
> are protocols? I copied a function from the source that can tell if something 
> is a protocol if written directly in clojure, but does not work on the 
> results from those methods.
>
> (defn protocol?
>   [maybe-p]
>   (boolean (:on-interface maybe-p)))
>
> Cheers,
> Bob
>
>
>
> > -S
> > clojure.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
>
> ----
> Bob Hutchison
> Recursive Design Inc.http://www.recursive.ca/
> weblog:http://xampl.com/so

-- 
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