On May 16, 4:32 pm, Saptarshi <saptarshi.g...@gmail.com> wrote:
> Hello,
> I am totally new to Clojure and have dabbled in Scala. In Scala, it is
> possible to override the + operator ,e.g a class A can overide +.
> In Clojure, I would have a struct and not a class. Can I still
> override the + operator in Clojure?
>

In Scheme, you can do this -- define another name for the original +,
and then redefine the original + to be a generic function (in
implementations that support it) or a normal function that delegates
to the original + if the inputs are numbers. There are performance
penalties involved, of course.

In Clojure, it is possible to do the former -- (def orig+ +) -- but it
appears that overriding a clojure.core definition is not possible. I'd
love to be wrong on this, though.

user=> (def + -)
java.lang.Exception: Name conflict, can't def + because namespace:
user refers to:#'clojure.core/+ (NO_SOURCE_FILE:5)

Regards,

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