Hi,
This is my first question here. I asked the question on SO, got no answer.
So I started a project with lein new app. I added a dependency in the project.clj([org.clojure/data.json "2.0.1"])
In core.clj I require the library as follows: (:require [clojure.data.json :as json])
when I try to use the library in: (def posts (json/read-str (slurp "../data.json") :key-fn keyword))
it throws this error: CompilerException java.lang.RuntimeException: No such namespace: json, compiling:
please let me know what step I am missing here. please explain the process of running the whole thing as if you’re talking to a 5 year-old!!!
All of the steps you describe sounds good, but they depend a little bit on some of the context around them. If you are willing to publish your complete code and directory structure in a small Github repository, for example, and whether you are using Leiningen or the Clojure CLI tools (or something else), that might help others help you spot the problem more quickly.
Hey @duzunov I am using Atom and I tried to evaluate the ns function and I get this error: FileNotFoundException Could not locate clojure/data/json__init.class or clojure/data/json.clj on classpath
Could do you tell me how you evaluate the ns function? (what editor you’re using?)
Thanks
Hi! I’m using Emacs+CIDER. I don’t know what is your editor setup, however as a principle before you evaluate commands you need to start a REPL (which includes getting any dependencies) and then to connect/“jack-in” to it.
I can suggest to try the following first - run lein repl first, and if you don’t have any errors type in your program there, form by form.
Adding a dep in project.clj or deps.edn doesn’t automatically add it to your running JVM. So you need to restart your REPL or look into the add-libs branch of tools.deps, or for Lein projects I think it’s pomegranate?
Hi! it’s working now. Here’s what I did: I used Emcas-Cider. I opened a repl. I loaded the buffer in the repl. then from the repl, I called the function that calls the json library. And it works.
So I guess maybe I’m missing some plugin /config in Atom. Anyway, I will stick to Emacs for the moment till I figure out what’s going on with my Atom config.
thank you anyway for your help, you definitely guided me into the right solution!
Right, thanks. Have you tried Chlorine? I believe proto-repl is abandoned (also, I’m the author of Chlorine, so maybe I can help you better with it).
Even then, it’s strange - seems like a dependency problem that is not dependent of the current editor plug-in you’re using…