这是我的project.clj
:
(defproject fixurls "0.1.0-SNAPSHOT"
:description "Fixurls"
:url "https://github.com/swizzard/fixurls"
:license {:name "WTFPL"
:url "http://www.wtfpl.net/"}
:dependencies [[org.clojure/clojure "1.5.1"]
[clj-http "0.9.2"]
[org.clojure/data.json "0.2.4"]
[me.raynes/fs "1.4.4"]
]
:plugins [[lein-gorilla "0.2.0"]]
:jvm-opts ["-Xmx4g" "-Xms2g" "-Xss1g" "-server"]
:main ^:skip-aot fixurls.core
)
此处~/clojure-stuff/fixurls/src/core.clj
:
(ns fixurls.core
(:require
[clj-http.client :as client]
[clojure.string :as string]
[clojure.java.io :as io]
[me.raynes.fs :as fs]
[clojure.data.json :as json]
)
(:import [java.net URL])
(:gen-class)
)
...
(defn process-file [in-file] (spit (get-fixed-name in-file)
(update-file in-file)))
(defn process-files [] (map process-file valid-files))
(defn -main [] (do (println "Hello, world!") (process-files)))
当我运行lein run
时,所有发生的事情,暂停后,是Hello, world!
打印到stdout
,然后lein退出。我已经独立验证了(process-files)
-main
部分未被调用。我可以从repl运行(-main)
,它可以正常工作。我做错了什么?
答案 0 :(得分:3)
map
函数是惰性的,除非访问相应的输出,否则不保证处理任何输入。如果您仅使用map
副作用,请将其包含在dorun
中。如果您还需要结果,请使用doall
强制处理整个输入。