I've almost completed a Complex (and Imaginary) basic type in a fork
of clojure. It turns out that it was a bit more effort that I had
originally indicated. I'll save the implementation details for the
clojure-dev group, but here is a quick run-down of the "interface",
such as it is:

1.) Added two classes: clojure.lang.Complex & clojure.lang.Imaginary
(These do not extend Number)
2.) Added and modified the core java code related to the basic
mathematical operations to allow Complex and Imaginary to
s(cr)eamlessly integrate with the existing Number types. You can +, -,
*, / with the existing types.
3.) Comparison operations are not implemented for Complex & Imaginary.
Note: The exception reported is currently a ClassCastException, which
is the default if you try to compare anything that isn't Comparable.

user=> (< "foo" "bar")
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)
user=> (< 3i 4i)
java.lang.ClassCastException: clojure.lang.Imaginary cannot be cast to
java.lang.Number (NO_SOURCE_FILE:0)

4.) Added pattern matching for parsing complex numbers in a very
flexible way. You can use any Number type (even ratios!) as the
imaginary and real parts of the Complex and Imaginary numbers. The
formatting of a complex number is natural:
3+4i, 4/5i, 2.12+2/3i, etc. and you can prepend 'i', 'I', 'j' or 'J'
to indicate the imaginary part. As with properly formatted doubles and
floats, there must be no whitespace between the numbers and the '+' or
'-' sign. The '+' or '-' in the format of a complex is not an infixed
operator! :-)
5.) Results of the real and imaginary parts follow Clojure conventions
for producing Ratios:

user=> (/ 6+6i 5)
6/5+6/5i
user=> (/ 6+6i -5)
-6/5-6/5i
user=> (/ 6+6i 5i)
6/5
user=> (/ 6+6i -5i)
-6/5

This is mostly working, but is beta. There are a few known bugs:
1.) Parsing of floats and doubles with sign included in the mantissa
seems to be a bit off.
2.) 44 tests fail when I run 'ant test'
3.) I need to create tests for correctness of operations.

Overall, I would estimate that I'm about 80% done with a error-free
implementation, but the basic behavior of the Complex type works. I've
put somewhere in the neighborhood of 60 hrs into it so far, so it's
been a relatively small effort but I've had to touch some rather
obtuse code.

I'm a n00b with git (but experienced with cvs and svn); I'm still
trying to figure out how to push my local git repository changes to
the fork I created on github. Can anyone help me there?

The fork on git-hub is:

git://github.com/travis-a-hoffman/clojure.git

I created a branch locally "complex_type", and have done git commit -a
with my changes. I can't, however, seem to push my changes back to
github:

~/Projects/HackingClojure/workspace/clojure> git push
fatal: remote error:
  You can't push to git://github.com/travis-a-hoffman/clojure.git
  Use g...@github.com:travis-a-hoffman/clojure.git

Using  the recommended doesn't help:

~/Projects/HackingClojure/workspace/clojure> git push
g...@github.com:travis-a-hoffman/clojure.git
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Cheers,

Travis

-- 
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