My background includes 10 years of common lisp so now I am learning Clojure by writing a symbolic math package with vector (i.e. a, b, c) and Nvector bindings (ab, ac, bc, etc) in namespaces, with the print method defined for these objects.
So when I wrote my deftests in the bottom of the same file as where the binding functions, I had to write (declare a b ab) to avert compiler warnings (which makes perfect sense).
(def G3 (doall (ga-bindall "a b c")))
galg.core=> G3
(+a +b +c +a*b +a*c +b*c +a*b*c +a*b +a*c +b*c +a*b*c)
galg.core=> [a +a -a ab +ab -ab a*b +a*b -a*b abc]
[+a +a -a +a*b +a*b -a*b +a*b +a*b -a*b a*b*c]
(deftest galg-vectors
(declare a b ab) ;<=== required when in same file as definitions
(testing "GALG Vector, Nvector and Sum tests."
(is (= (Vector 'a) a))
(is (= (Vector 'a -1) -a))
(is (= ab (Nvector 'a 'b)))
(is (= (+ 1 a ab) (Sum 1 a ab)))
))
Then when I cleaned up my code by moving the tests to, galg.core-test file as here:
(ns galg.core-test (:use clojure.test galg.core)) ;;<== imports a, b, ab, etc
(deftest galg-vectors
;(declare a b ab) ;<=== must be removed when in separate file
(testing "GALG Vector, Nvector and Sum tests."
(is (= (Vector 'a) a))
(is (= (Vector 'a -1) -a))
(is (= ab (Nvector 'a 'b)))
(is (= (+ 1 a ab) (Sum 1 a ab)))
))
... then, the "already refers to:" compiler error occurs when the (declare a b ab) is present:
CompilerException java.lang.IllegalStateException: a already refers to: #'galg.core/a in namespace: galg.core-test, compiling:(NO_SOURCE_PATH:2:3)
This error seems a bit excessive, since from my thinking, "declare" is really the "promise of a binding" for the compiler, without really defining one.
Any thoughts?