First item of business - there are no operators, operators are functions. I think the Clojure way to do this is via multimethods: http://clojure.org/multimethods
I might just be naive, but it seems like more of core would need to be implemented as multimethods in order to do this. Has this come up before? On Sat, May 16, 2009 at 5:14 PM, Michel S. <michel.syl...@gmail.com> wrote: > > > > 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 -~----------~----~----~----~------~----~------~--~---