Search code examples
clojurecompilationcompiler-warnings

Getting more useful warnings when compiling Clojure


In the function bellow, I used cond in the place of case. It took me a long time to single out this function. I am learning clojure, so the error was not obvious to me. When I tried to run the code up to the map function (using the cursive/Intellij debugger), Intellij complained: There is no executable code at core.clj:144. If the clojure compiler knows that, is there an option to get a warning at compiler time? Are there other checks that the compiler (or a lint) can do in my code?

(defn uri-gen [uri fields line]
  (let [remo "[//\\:*?()<>|.%'\"&]"]
    (cond (count fields)
      0 (correct-uri ...)
      1 (let ...)
      (correct-empty
        uri
        (apply str
          (map (fn [it] ...)))))))

Solution

  • Unfortunately, compiler warnings & error messages in Clojure are often terse, nonsensical, or just plain missing.

    I'm not sure if it would help in this instance, but you might try the eastwood Clojure lint tool (see others in the Clojure Toolbox). I also make extensive use of Plumatic Schema which has helped me to avoid many simple type errors.