【发布时间】:2015-10-26 23:21:23
【问题描述】:
我从here 为练习 2 创建了一个 Leiningen 项目。我的代码如下所示:
(ns random-quotes.core
(:require [clojure.string :as str])
(:gen-class))
(defn word-count [s]
(frequencies (str/split (first (str/split s #"\n")) #"\s")))
(def quote-url "http://www.braveclojure.com/random-quote")
(def total-word-count (atom {}))
(defn update-word-count []
(future
(swap! total-word-count
(partial merge-with +)
(word-count (slurp quote-url)))))
(defn quote-word-count [n]
(doseq [quote-future (doall (repeatedly n update-word-count))]
@quote-future)
@total-word-count)
(defn -main [n]
(doseq [entry (sort-by val (quote-word-count (bigdec n)))]
(println entry)))
一切都非常简单。当我运行时,例如lein repl 中的(-main 5),它会按预期运行、打印和返回。但是,当我尝试使用 lein run 5 时,它会运行并打印但从不退出,所以我不得不使用 Ctrl+C 来恢复我的终端。
知道为什么会这样吗?
【问题讨论】: