Hi,

Am 03.06.2010 um 21:51 schrieb Laurent PETIT:

>> (in-ns 'some.other.namespace)
>> 
>> (let [orig-x some-x]
>>  (defn some-x
>>    [foo]
>>    (if (my-foo? foo)
>>      (do-stuff foo)
>>      (orig-x foo))))
>  
> Sorry Meikel, but I'm having trouble following you today.
> Does the above example stand for "pseudo-code" for explaining what happens 
> when one reimplements a protocol (in which case I'm pretty sure you're wrong 
> - redefining a protocol extension on a type redefines it for all following 
> calls, from any thread), or does the above example stand for pseudo-code for 
> how one would "try" to "break the rule" (mentioned by Christophe, Rich, and 
> others) in a (hopefully) non-intrusive way ?

The above is working code (modulo foo related implementations). You can at any 
moment change namespaces. Change some function there and go back to your 
original namespace. This is effectively monkey-patching. This works now.

So now suppose seq does not support strings. Someone goes in to "fix" this in 
his library. Say, his fix returns (\f \o \o). Someone else also "fixes" seq: 
("f" "o" "o"). You load both libraries and are in trouble. The same happens if 
both extend the Sequable protocol for j.l.String.

So extending a protocol you don't own to a type you don't own is like going 
into someone else's namespace and "fixing" things there. Not doing so is a 
question of good manners, which are in general lacking nowadays… So let's hope 
that we are all well-behaved and don't adopt such techniques.

Sincerely
Meikel

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