I think the best bet would be implementing them in Clojure itself. I'm saying this because otherwise it would really get harder given the constraints regarding immutability. Furthermore, the implementation should, I think, be generic, that is, we should be capable of creating complex numbers, the real and imaginary parts of which can be integers, rationals, or reals. For instance, it sould be possible to do this:
(1/3 + 2/5i) + (1/2 + 1/10i) = (5/6 + 1/2i) without any loss of precision due to type conversion (ex. towards float). So, from what I gather, a good choice might be to use structures, and perhaps multimethods. Rich, would it be possible to "overload" the arithmetic operators with this strategy, so that they'll work with the new complex numbers? Opinions? On Nov 23, 3:42 pm, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Nov 23, 8:56 am, Rock <[EMAIL PROTECTED]> wrote: > > > > > On Nov 23, 2:37 pm, André Thieme <[EMAIL PROTECTED]> wrote: > > > > On 23 Nov., 13:29, Rock <[EMAIL PROTECTED]> wrote: > > > > > I've just noticed there is no support for complex numbers in Clojure. > > > > There are a few posts on the issue here, but no rationale. I'm a > > > > mathematician, and complex numbers pop up all over the place. CL and > > > > Scheme have always had native support for them. I took it for granted > > > > they were there until I needed them recently. > > > > I think the reason is, that Java still does not have them in its > > > standard lib. It puzzles my why they didn’t come up with > > > something in the past 13 years. > > > If you want them you will have to use some lib for that. > > > Yes, I see, but the JVM hasn't got native support for rational numbers > > either, and yet we do have them in Clojure thanks to the Ratio class > > Rich created. I can't see why something analogous can't be done for > > complex numbers as well. We even have unbound integers! And you don't > > have them in Java natively. Maybe, for the time being, some Complex > > class like the ones found in Apache.Commons or in JScience could be > > incorporated into Clojure, so that we have a common basis to work on, > > and there would be compatibility among different people's code > > (somthing important I believe). > > I have nothing against complex numbers, and interested parties should > contribute to this discussion on how best to incorporate them in > Clojure. The issues are: > > What support is required? > How hard to do with no other libs, a la Ratio? > If a 3rd-party lib is required, which one, what's the license, how to > make it optional, how well does it fit with Clojure's immutability > requirements, etc. > > I'm amenable to a patch after consensus, but it's not something I have > time to do myself. > > Rich --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---