-
Notifications
You must be signed in to change notification settings - Fork 60
Description
I'm not sure why, but running the unit test (from leiningen) causes an exception in the SELECT macro in sql.clj.
Exception in thread "main" java.lang.IllegalStateException: Attempting to call unbound fn: #'joy.sql/apply-syntax, compiling:(joy/sql.clj:101:3)
I get the same error loading the file directly in the repl:
user=> (load-file "src/clj/joy/sql.clj")
CompilerException java.lang.IllegalStateException: Attempting to call unbound fn: #'joy.sql/apply-syntax, compiling:(/Users/owen/Projects/joyofclojure/src/clj/joy/sql.clj:101:3)
edit
I figured it out... This error is because the call to partial in the definition of clause-map captures the unbound value of apply-syntax and does NOT get the new value when it is re-declared. The problem can be demonstrated in the repl:
user=> (declare foo)
'user/foo
user=> (def ^:dynamic foopar (partial map foo))
'user/foopar ;; symbol foo resolves ok, without using declare this would be an error
user=> (foopar [1 2 3])
IllegalStateException Attempting to call unbound fn: #'user/foo ;;s error as expected
user=> (def foo #(+ 1 %))
'user/foo
user=> (foopar [1 2 3])
IllegalStateException Attempting to call unbound fn: #'user/foo ;; still an error!
user=> (def ^:dynamic foopar (partial map foo)) ;; redefine partial entirely
'user/foopar
user=> (foopar [1 2 3]) ;; now it works, using the new bound value of foo
(2 3 4)
One simple fix is to just (declare clause-map) instead of (declare apply-syntax). Pull request incoming. Maybe there's a better way to fix it though?