Namespace loading with deftype/defrecord used from Java

98 views
Skip to first unread message

Warren Lynn

unread,
Jun 17, 2012, 2:13:05 PM6/17/12
to Clojure
Basically, the issue is:

When a deftype/defrecord named class is used from Java, its containing
namespace is not loaded automatically, so even calling a function in
the same namespace will raise an exception like this:

java.lang.IllegalStateException: Attempting to call unbound fn ...

An example:

(ns my-ns.core)

(defn test-func []
)

(defrecord testrec []
ITestProtocol
(init [this]
(test-func)))

In Java side, the below will fail:

rec = new testrec();
rec.init();

with an exception raised
java.lang.IllegalStateException: Attempting to call unbound fn #'my-
ns.core/test-func.

This issue was raised before about 1 and half year ago here:
https://groups.google.com/forum/#!msg/clojure-dev/4CtSVWcD15A/shpMuyjMpxsJ

And a work-around is provided, like here:
http://stackoverflow.com/questions/10953621/clojure-deftype-calling-function-in-the-same-namespace-throws-java-lang-illegal

It took me hours to figure out the problem as everything works fine in
REPL itself.

Does anybody know if this issue will be addressed? Thank you.
Reply all
Reply to author
Forward
0 new messages