I have tried using require to get external libraries into my working name space but I keep getting the error
"java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol (logging.clj:13)"
Below is my code snippet.
(ns com.my.project.mytest
(:require (clojure [zip :as zip]
[xml :as xml])
(clojure.contrib [logging :as log])))
Now the thing is I haven't changed anything in the logging library and my above declarations used to work before I changed machines. What could be wrong?
Related
If I add the following require:
(ns project.core
(:require
[compojure.route :as route])
(:gen-class))
(defn -main [& {:as args}]
(println "hello"))
an do
lein run
I get
Syntax error macroexpanding clojure.core/ns at (ring/util/mime_type.clj:1:1).
((require [clojure.string :as str])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
is there a way I can get
"compojure.route not found; not defined; or whatever" e.g. something meaningful?
if I remove it it works fine. e.g. it says Hello
using Leiningen 2.9.4 on Java 14.0.1 OpenJDK 64-Bit Server VM
The project you are using is using very old dependencies. Clojure spec (introduced "recenlty") added macro/compile time checks and the mentioned file there triggers it.
compojure.route actually is found and it then requires its transitive deps. And while going down the chain ring.util.mime-type is required and the version you are using is not ready for current Clojure versions.
Your best bet here is to upgrade your deps. E.g. if you are following a book or if you are using a template this things can happen. If you have lein-ancient installed, it can attempt the update for you. Otherwise your best bet is to start in your project.clj and compare versions (e.g. check clojars).
If the problem still persists, have a look at lein deps :tree and see what is going on with the transtive deps.
I am trying out the function (starts-with?) shown here: https://clojure.github.io/clojure/clojure.string-api.html and when I try to use it I get Unable to resolve symbol: starts-with? in this context error message . I modified my project dependencies too by specifying :dependencies [[org.clojure/clojure "1.8.0"]] but that didn't seem to help.
You may have forgotten to require the namespace ? See the example below:
(ns simple.strings
(:require [clojure.string :as str]))
(str/starts-with? "hello, world" "hello")
; true
I am pulling my hair out trying to resolve the following error:
Exception in thread "main" java.io.FileNotFoundException: Could not locate composer/midi/short_message__init.class or composer/midi/short_message.clj on classpath: , compiling:(events.clj:12:1)
The reference to short-message is in the namespace declaration of events.clj:
(ns composer.ui.events
(:use [seesaw core border chooser])
(:require [composer.midi
[io :as io]
[time :as time]
[player :as player]
[short-message :as short]]))
And here is the namespace declaration of short-message itself in short-message.clj:
(ns composer.midi.short-message
(:require [composer.algorithm.transform :refer :all]
[composer.algorithm.markov.transform :refer :all]
[composer.midi [io :refer :all] [message :as message]]))
short-message is in the same directory as all other files in composer.midi, and yet this seems to be the only one that is resulting in an issue. Indeed, after verifying the target directory in my project, this is the only namespace which doesn't seem to contain a corresponding class file. I thought it could be an error with the code, but if I try to load the file with (load-file "src/composer/midi/short-message.clj") at the REPL I don't have any issues.
Your comment is right. In clojure dashes in namespaces correspond to underscore in filenames. So your file name should be short_message.clj as you found.
in one file (core.clj) I have
(ns nac.core)
(def bar "something")
And in another file in the same directory, I have
(ns nac.io
(:require [nac.core :as c]))
(defn foo [] c/bar)
Upon evaluation I get an error saying
Unable to resolve symbol: c in this context
So the file is found in the require, but the namespace as I have named it is not.
What am I missing here? Thanks.
I download the clojure 1.2 and clojure-contrib-1.2.0.jar from the download site.
And I found the info about the math functions.
As is shown in the example, I tried to run the code.
(ns your-namespace
(:require clojure.contrib.generic.math-functions))
(println (abs 10))
But, I got the following error, when I run as follows.
CLOJURE_JAR=/Users/smcho/bin/jar/clojure.jar:/Users/smcho/bin/jar/clojure-contrib-1.2.0.jar
java -cp $CLOJURE_JAR:$CLASSPATH clojure.main SOURCE.CLJ
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: abs in this context (hello.clj:4)
at clojure.lang.Compiler.analyze(Compiler.java:5205)
...
at clojure.main.main(main.java:37)
Caused by: java.lang.Exception: Unable to resolve symbol: abs in this context
at clojure.lang.Compiler.resolveIn(Compiler.java:5677)
at clojure.lang.Compiler.resolve(Compiler.java:5621)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:5584)
at clojure.lang.Compiler.analyze(Compiler.java:5172)
... 25 more
What might be wrong?
Try :use instead of :require
(ns your-namespace
(:use clojure.contrib.generic.math-functions))
(println (abs 10))
10
nil
Require makes the symbol (abs in this case) available, but you'd have to fully qualify it. Use imports the symbol into "your-namespace":
(ns your-namespace2
(:require clojure.contrib.generic.math-functions))
(println (clojure.contrib.generic.math-functions/abs 10))
10
nil