Given that this seems to bite quite a few people who try to use defrecord / import (even if it only bites them once), perhaps it would be a nice enhancement for import to allow hyphen and automatically translate it to underscore in the package / namespace? It seems very inconsistent given that the record name _can_ have hyphens, according to Don's tests...
(I haven't run into this, having not used defrecord, so I'm making this suggestion based purely on observing people complain about this sort of thing...) Sean On Fri, Dec 2, 2011 at 1:44 AM, Don Jackson <cloj...@clark-communications.com> wrote: > > I was using defrecord for the first time, to create a type that I wanted to > throw+ via slingshot to signal errors from a library. > > I'd seen an example of this in another library, and I pretty much just cut > and pasted it into my project. > > I understood that I need to explicitly import the resulting class into > clients that use my library, and attempted to do so. > > When loading the client library that uses and imports, I got this: > > foo-bar.core.foo-bar-error > [Thrown class java.lang.ClassNotFoundException] > > Restarts: > 0: [QUIT] Quit to the SLIME top level > > Backtrace: > 0: java.net.URLClassLoader$1.run(URLClassLoader.java:202) > 1: java.security.AccessController.doPrivileged(Native Method) > 2: java.net.URLClassLoader.findClass(URLClassLoader.java:190) > 3: clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61) > 4: java.lang.ClassLoader.loadClass(ClassLoader.java:306) > 5: java.lang.ClassLoader.loadClass(ClassLoader.java:247) > 6: java.lang.Class.forName0(Native Method) > 7: java.lang.Class.forName(Class.java:169) > 8: > factmigrate.core$eval1645$loading__4414__auto____1646.invoke(core.clj:1) > 9: factmigrate.core$eval1645.invoke(core.clj:1) > --more-- > > After a LOT of time and experimentation, I finally realized that in my > import statement, I need to replace the hyphen character in my namespace > (let's call my namespace foo-bar.core) > to an underscore. > > So in a client of my library, it needs to do something like this > > (ns foobarclient.core > (:use foo-bar.core) > (:import foo_bar.core foo-bar-error)) > > Assuming that somewhere in the foo-bar.core namespace I had done something > like this: > > (defrecord foo-bar-error [blah1 blah2]) > > I am still recovering from this debugging session, but my current thought is > that this was all my fault, and I just need to be smarter about Java interop > and naming issues. > The hyphen/underscore issue is mentioned here: > > http://clojure.org/libs > > > Lib Conventions > Clojure defines conventions for naming and structuring libs: > > A lib name is a symbol that will typically contain two or more parts > separated by periods. > A lib's container is a Java resource whose classpath-relative path is > derived from the lib name: > > The path is a string > Periods in the lib name are replaced by slashes in the path > Hyphens in the lib name are replaced by underscores in the path > > > But I did not find this right away, and even after I did find it, it was not > immediately obvious to me what the implication was in an import statement. > > So, I simply wanted to document this for the mailing list, in the hope of > preventing others from stumbling into this, and maybe if they do, they will > find this > explanation in their searches… > > Don > > -- > 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 -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- 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