As far as I understand, your example with Math/abs would need to be part of
Java.

You cannot extend the arithmetic operators in Java, and you will not be
able to extend static Java methods like Math/abs.

What you may be able to do is make your custom type play nice with Clojure
operators, like Clojure's rationals and bignums.

I'd suggest looking at the code for these, and considering a Java class
with two primitive attributes rather than a Clojure vector or map (which
have a big overhead compared to a simple number). Depending on what you
want to do, you may also want to consider implementing a "vector of
complex" type, which could be a single object with two primitive arrays.

If you're targeting a performant implementation, you should probably cross
post to numerical-clojure; people over there have a lot of experience about
numerical optimizations in Clojure.

On Monday, 27 April 2015, 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
> <javascript:_e(%7B%7D,'cvml','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
> <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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
> <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@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