On Friday, January 23, 2015 at 3:13:08 PM UTC-5, Tassilo Horn wrote:
>
> philli...@newcastle.ac.uk <javascript:> (Phillip Lord) writes: 
>
> >> I use satisfies? for optional features, e.g., if some data structure 
> >> satisfies some protocol, then that optional feature is enabled, else 
> >> it's disabled.  But that's not really on a hot path so I don't care 
> >> much about satisfies? performance. 
> > 
> > Have you tried just implementing the protocol over Object to do 
> > nothing? Then putting use an alternative implementation of the 
> > protocol where you want. 
>
> I really use it for optional features for which no alternative 
> implementation exists.  Concretely, I have a library that can work with 
> several graph data structures in a uniform way.  Some of them have 
> first-class edges, others only have references.  For example, my lib has 
> a code generation facility where there's some code like 
>
>   (when (satisfies? IEdges type-graph) 
>     (generate-edge-access-fns ...)) 
>
> But for other stuff I do extend protocols to Object (and nil) providing 
> a default implementation. 
>
> Bye, 
> Tassilo 
>

One approach is to have a first-class-edges? method in the mother graph 
protocol. Another is to have such a method in IEdges and extend that to 
Object with first-class-edges? returning false and the other 
IEdges-specific methods throwing IllegalStateExceptions, as well as to 
"true" IEdges subtypes with the first returning true and the rest doing 
whatever they should do.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to