Yeah, that's another good example where a protocol might be helpful. 

Arguably, you could make a case for nearly all of Clojure's abstractions 
being backed by a protocol. It has certainly proved to be a very useful 
technique in core.matrix

I don't think there's even much performance downside of doing so: the 
dispatch code can just check if an object is of the right interface e.g. 
(instance? IMeta foo) and only if that fails then fall back to a 
protocol-style dispatch lookup.

On Saturday, 31 August 2013 13:53:20 UTC+8, Colin Fleming wrote:
>
> I've also been interested in this for Named (a protocol for things I can 
> call "name" on), although my use-case is mostly interop with Java 
> frameworks.
>
>
> On 31 August 2013 15:13, Mikera <mike.r.an...@gmail.com <javascript:>>wrote:
>
>> It would be better, I think, if metadata was attachable via a protocol 
>> rather than than a wrapper: then you could just extend the protocol to any 
>> arbitrary Java class. Wrappers are a pain to make work because of wrapping 
>> / unwrapping and protocols also have the advantage of being very efficient.
>>
>> I've wanted a similar feature with respect to "seq" as well (a protocol 
>> for things that can be treated as sequences)
>>
>> On Saturday, 31 August 2013 03:16:26 UTC+8, JvJ wrote:
>>>
>>> I've noticed that, when doing a lot of Java interop, it's impossible to 
>>> attach metadata to most Java objects, since they don't implement the IMeta 
>>> interface.  A workaround for this would be to do something like put every 
>>> Java object in a single-element list and attach metadata to the list, but 
>>> this is annoying.  Would it be possible (or even useful) to create some 
>>> kind of generic IMeta structure that can wrap other Java objects and have 
>>> them act like normal, except for the added metadata (or even other 
>>> Clojure-esque features)?
>>>
>>  -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
-- 
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/groups/opt_out.

Reply via email to