Possible Duplicate:
Why does require in the ns form behave different from the require function
I am dabbling in clojure and have run into a problem with importing. From the REPL
clojure.core=>(import '(java.io FileReader))
clojure.core=>(import 'java.io.FileReader)
clojure.core=>(import java.io FileReader)
each work perfectly, but from file only the following works:
(ns project.core
(import java.io.FileReader))
These each fail
(ns project.core
(import 'java.io.FileReader))
(ns project.core
(import '(java.io FileReader))
with the following errors:
ClassNotFoundException quote.java.io.FileReader java.net.URLClassLoader$1.run (URLClassLoader.java:366)
ClassNotFoundException quote.(java.io FileReader) java.net.URLClassLoader$1.run (URLClassLoader.java:366)
respectively.
In reality I need to import more than just java.io.FileReader, but this is a distilled version of the problem.
Any ideas what might be going wrong? I can’t seem to find the problem anywhere else
The solution is:
As to why this is necessary, the
nsmacro accepts several directives, including:import. Due to the way the macro is implemented, it expects arguments to the import directive to be in a list-like form – hence,[java.io ...]. Incidentally, a list such as(java.io ...)would work just as well.For a complete rundown of how to use
ns, please take a look at the ClojureDocs page: http://clojuredocs.org/clojure_core/clojure.core/ns. ClojureDocs is an invaluable resource for these sorts of problems.