Unless the Java Math library handles complex types already, I don't know of
any way to extend it in a way that would let you get the answer you want
from (Math/abs my-complex-number) in Clojure.

If you want code that gives the correct answers, a library using vectors or
maps for complex numbers can get you there.  Memory footprint and
performance should be better with Clojure records or a new class written
directly in Java.  With a library, I don't know of any way to be able to
mix Clojure's arithmetic operations like + - * / etc. with its existing
numeric types, and your new library-implemented complex types.

Support of Clojure's arithmetic operations on complex numbers might only be
achievable by modifying Clojure itself.  Depending upon your goals, the
down side of that approach is that it will not become part of the normal
Clojure distribution unless the Clojure core team wants that addition,
which I would guess would be very low on their priority list (just a guess
-- I have no inside knowledge there).

Andy

On Mon, Apr 27, 2015 at 8:39 AM, endbegin <nkripl...@gmail.com> wrote:

> I have been thinking along the lines of mikera and Maik - and it seems
> like there is no further progress here? I would like to take a crack at
> creating a complex number type, but implemented as a library to Clojure. I
> am not sure where to start, and if anyone here has suggestions, I'd be
> happy to hear them.
>
> A complex number could simply be a vector of two elements, or a map with
> :real and :imag keys (or something lightweight) - and I am not sure what it
> would require to make this type work happily with code arithmetic functions
> in Clojure and Java Math.
>
> It would also have to work with seq operations in Clojure - for instance:
> If I have a complex number c = {:real 3 :imag 4}, and a vector v = [1 -2
> c], it would be nice to have the call 'map #(Math/abs %) v' produce (1 2
> 5).
>
> I am having trouble figuring out all the pieces that need to be
> implemented. Is it even possible to implement this as a library, or does
> this need to be a part of clojure.core?
>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to