Leiningen Uberjar different results from lein run

My application runs when I run it in the clojure repl or using leiningen repl but when i create a jar using uberjar and run the application it only reads the first 2 records of my collection.

I tracked it down to pmap so I created the simplest possible use of pmap and it gets wierder. why does this work

(ns ktest.core
    (:gen-class))
(defn -main []
  (println (pmap identity (range 20))))

but not this

(ns ktest.core
        (:gen-class))
    (defn -main []
       (pmap #(println %) (range 20)))

you have been bitten by "the lazy bug". pmap creates the sequence that when read will compute the results. when you run this with the println it reads the results so it can print them, thus triggering the evaluation. In this case you can fix this will doall or dorun . If you only need the printing side effects of running it then choose dorun , if you need to do something with this result then choose doall which keeps the results in memory.

(dorun (pmap #(println %) (range 20)))

a couple items get printed because of chunked sequences. see this Jira issue for details on pmap and chunked sequences.

链接地址: http://www.djcxy.com/p/51732.html

上一篇: 图标消失在用Leiningen制作的uberjar中

下一篇: Leiningen Uberjar lein run的不同结果