Re: Override the + operator for a 'struct'

2009-05-17 Thread bradford cross
On Sun, May 17, 2009 at 1:40 PM, philip.hazel...@gmail.com < philip.hazel...@gmail.com> wrote: > > On May 17, 1:14 am, "Michel S." wrote: > > 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

Re: Override the + operator for a 'struct'

2009-05-17 Thread philip.hazel...@gmail.com
On May 17, 1:14 am, "Michel S." wrote: > 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 + becau

Re: Override the + operator for a 'struct'

2009-05-17 Thread Konrad Hinsen
On 17.05.2009, at 03:43, bradford cross wrote: > 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

Re: Override the + operator for a 'struct'

2009-05-17 Thread Meikel Brandmeyer
Hi, Am 17.05.2009 um 03:43 schrieb bradford cross: 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 impl

Re: Override the + operator for a 'struct'

2009-05-16 Thread Adrian Cuthbertson
>Yes, the general consensus is that basic math needs to be as fast as >possible, even at the expense of some flexibility. It's worth noting here that one can also use binding to override other than arithmetic core functions; (defn ustr [s] (binding [clojure.core/str (fn [x] (.toUpperCase x))]

Re: Override the + operator for a 'struct'

2009-05-16 Thread Phil Hagelberg
bradford cross writes: > 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 multimeth

Re: Override the + operator for a 'struct'

2009-05-16 Thread Trevor Caira
One way to accomplish this is via :refer-clojure in ns. Usage is like: (ns test (:refer-clojure :exclude [+])) This would allow you to, for example, dispatch the implementation based on the type of the first argument via multimethods (as Michel S. noted, at a performance penalty). The origina

Re: Override the + operator for a 'struct'

2009-05-16 Thread bradford cross
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

Re: Override the + operator for a 'struct'

2009-05-16 Thread Michel S.
On May 16, 4:32 pm, Saptarshi 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

Override the + operator for a 'struct'

2009-05-16 Thread Saptarshi
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? Regards Saptarshi --~--~-~--~~---