2011/12/21 Marek Kubica <ma...@xivilization.net>

> Hi,
>
> Thanks for your mail, glad to get ideas so fast :)
>
> On Wed, 21 Dec 2011 09:51:04 +0100
> Linus Ericsson <oscarlinuserics...@gmail.com> wrote:
>
> > I would def a protocol CustomArithmetics and include the the
> > nescessary methods for arithmetics, and then a deftype for each
> > custom arithmetics. It would be possible to extend the protocol for
> > Longs and Integers as well, if needed.
> >
> > If you would like to use the normal operator-names +,- etc then make
> > sure that exclude those in the ns-declaration where I would use
> > refer :exclude ... and then redefine them as above.
>
> So I'd have to exclude them, include them by some other name, and use
> them for the "normal" number types, so I don't break + for normal
> numbers, right?
>
> But that also means, that any consumer of my ranged numbers, would be
> forced to use my own version of +, - etc. Right? I'm exploring what is
> possible with Clojure, this is not anything that I actually need for
> something.
>
> Now I'm mostly speculating, but the reason one doesn't have the nice
Protocols around +,- etc already is because of efficiency. However, it
wouldn't be to hard to add a method for normal integers to call for the
ordinary clojure.core/+ in this particular case (even though they would
have quite sever performance losses).

For the customized algebra it would be easy to throw exception like "odd
result" when one made an unfortunate division on a number 4n+2 etc.

The main difference between Clojure and usual OOP seems to be that the
functions is not too connected to the data structures, which IMHO makes the
applications simpler to manage in some common use cases.

/Linus

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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