Note that there are some explanatory texts on larger screens.

plurals
  1. POswap! atom and then: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn
    primarykey
    data
    text
    <p>So, in my core.clj file I have: </p> <pre><code>(def page-buffer (BufferedReader. (InputStreamReader. (clojure.java.io/input-stream (clojure.java.io/resource "mitochondria.html"))))) (def parsed-page (atom "")) </code></pre> <p>and then later: </p> <pre><code>(defn -main [&amp; args] (let [port (Integer/parseInt (first args))] (swap! parsed-page (with-open [] (.toString (reduce #(.append %1 %2) (StringBuffer.) (line-seq page-buffer))))) (println "Server is starting") (println "port: " port) (run-server port))) </code></pre> <p>This compiles and then I turn it into an uberjar. But when I run it I get the line with swap! blows up: </p> <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn at clojure.core$swap_BANG_.invoke(core.clj:2106) at serve_pages_from_memory.core$_main.doInvoke(core.clj:29) at clojure.lang.RestFn.applyTo(RestFn.java:137) at serve_pages_from_memory.core.main(Unknown Source) </code></pre> <p>I tried this without using an atom and everything worked just fine (using a var defined with "def" to be a string) but eventually I want to send this var to multiple threads, so I need for this to be an atom or agent. </p> <p>What have I done wrong? </p> <p>UPDATE: </p> <p>Jeremy Heiler, thanks. Fixed, but the result is ugly as sin:</p> <pre><code>(defn parse-buffer [&amp; everything-else] (with-open [] (.toString (reduce #(.append %1 %2) (StringBuffer.) (line-seq page-buffer))))) (defn -main [&amp; args] (let [port (Integer/parseInt (first args))] (swap! parsed-page parse-buffer) (println "Server is starting") (println "port: " port) (run-server port))) </code></pre> <p>I have to give an argument to parse-buffer or I get an error. But I do not use the argument, so this is ugly. I must be writing this wrong, yes? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload