Noob question, using Win7 64-bit, Clojure 1.2.0, Java 1.6.0_22
When I start clojure from command line, pprint function is easily available.
user=> pprint
#<pprint$pprint clojure.pprint$pprint@16dfa45>
user=> (pprint "hi")
"hi"
nil
user=>
But when I try to use pprint from a file, I get an error. This happens with and without namespace (ns… :require…) as shown in pprint documentation
clj file as follows:
(ns whatevah
(:require clojure.pprint))
(pprint "hi")
Error as follows:
C:\Users\mischw\code\Clojure>java -cp ";c:\users\mischw\code\clojure\classes\*;c:\Program Files (x86)\Java\SWT;c:\users\mischw\code\clojure\classes\bookcode\*" clojure.main swinglearn.clj
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: pprint in this context (swinglearn.clj:14)
... 21 more
Output completed (0 sec consumed) - Normal Termination
I don’t understand the general idea of what’s going on here. Why does one work but not the other? Does that have to do with namespaces? Classpaths? Some other simple fix? Clearly noob questions, but I find this happens with a bunch of examples… I’m unable to run them even though it seems straightforward to import/use/require/include them.
You’re getting
requiremixed up withuseand/orimport.requirecauses the library to get loaded, and every public symbol it exports will be accessible as egclojure.pprint/pprint. If you want to use a more convenient name like justpprint, you need toreferto the namespace.useis a convenient shorthand for “require, then refer”, to load the library without the namespace prefix.Edit: Not sure why it’s working for you from the REPL. As you can see, it doesn’t work for me. I imagine you did some setup earlier that makes it work and then forgot about it, or possibly you have some init script that does this stuff for you at the REPL but not when loading from a file.