I forgot to mention it (and I guess I'll need a part 2 to fully explain some of the subtler points), but it's important to note that ANY class can be extended by these extension methods. Even java.lang.String and its ilk.
That wasn't exactly clear from the post, but it was already getting too long as it is.
One of the more legitimate uses I've found for monkeypatching is fixing bugs in libraries you don't control when the maintainer is for whatever reason unresponsive to your pleas. I.e. replacing someone's broken method despite lack of a pre-existing contract. Is that supported?
Every function in a protocol is namespaced. There's nothing preventing you from defining a new function with the same name in a different namespace. This doesn't actually replace anything, though, and any references to the old function will have to be changed to point to the new one.
It is also possible to extend a protocol a second time for a given type/record, which will overwrite the previous implementation. This can be occasionally useful (mostly for incremental development), but for the most part runs counter to the philosophy of Clojure. Seeing it used in production Clojure code would raise a lot of alarm bells.
So anything that requires changing all the references to the new one is a non-starter. I want something that lets me fix it in-place without going and hacking their source directly.
If you could do something like "monkey patch this, but only for calling code inside my private namespace" that would probably get you 90% of the way there.
No, I understand. I used monkeypatching to work around some problems with numerics libraries in Ruby too. But let's face it, it's not as good a technique as this. And I didn't even touch on the ability to fold a closure around a class instance using (reify ...) or the differences between declaring methods in deftype or using extend-type.
There is a lot of power in this relatively simple concept without going into the gnarly tilt-the-whole-world problems that monkeypatching introduces.
I'm not exactly defending monkeypatching. It's better than nothing, and if used judiciously it doesn't have to be especially dangerous. All the rope you need and all that...
And, what you're describing is very cool on its own merits.
What I want to know is whether this will get you out of the same messes that monkeypatching can. If it will, but in a more controlled way, then that's really awesome.
That wasn't exactly clear from the post, but it was already getting too long as it is.