Hi to everyone,
I know that may sound a bit mad, but I need this kind of abstraction
to keep my code as aligned as possibile to a legacy one.
I'm the developer of the clj3D library. I want to overload the "+"
function in order to be able to do this:
(+ "a" "b")
;=> "ab"
or this:
(+ [1 2] [3 4])
;=> '(1 2 3 4)
I was thinking to made it through protocols, this is an example:
user> (defprotocol Addable
(+ [t1 t2]))
Warning: protocol #'user/Addable is overwriting function +
WARNING: + already refers to: #'clojure.core/+ in namespace: user,
being replaced by: #'user/+
Addable
user> (extend-type String
Addable
(+ [s1 s2] (str s1 s2)))
nil
user> (+ "a" "b")
"ab"
This obviously works but I lose the original "+" function, so (+ 1 2)
will fail.
Is there a way to archive the requested behaviour without compromising
the original "+" and in an idiomatic way?
Best,
Alfredo
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en