As a user of Clojure interop from Java, I want defrecords (and deftypes?) to load their namespaces upon class initialization so that I can simply construct and use AOT'd record classes without manually requiring their namespaces first.
Calling the defrecord's constructor may or may not result in "Attempting to call unbound fn" exceptions, depending on what code has already been run.
This issue has been raised several times over the years, but I could not find an existing ticket for it:
Screened: Approach 2, which makes loading the namespace optional. This makes the change purely additive, whereas Approach 1 changes semantics (load ordering) of existing programs. I don't know why we would want that risk, especially when it is not clear that most users of deftype would even want ns loading side effect.
Approach 1: require the namespace a record/type belongs to during the record/type class init
Approach 2: like Approach 1 but does the automatic loading only when a :load-ns option is set to true in the deftype/defrecord
Note: patch for Approach 1 causes some generative tests to fail since the namespace used to evalaute a defrecord is immediately destroyed thus impossible to load
This is a bug in potemkin caused by the fact that it assumes deftype expands to an unqualified second argument.
The deftype* special form takes as first argument the tagsym and as a second argument the class name, potemkin passes a wrong second argument, it expands to :
I'll open a PR fixing this issue in potemkin and link back to this ticket.
Comment made by: hellonico
Has this been applied ? Seems like it still break on 1.8beta1 ...
Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'chapter01.core/shop-func
This commit was made for on Jul 17 2015, so it is definitely included in 1.8.0-beta1: https://github.com/clojure/clojure/commit/c8e248d84740dbe1538c6f86ff1ecc59e200d23a
I haven't checked exactly which of the attached patches that corresponds to, or whether it fixes the problem.
you'll have to set the :load-ns option to true in your defrecord declaration to make it work.