lein run exits without running all of my -main fun

2019-08-03 22:24发布

Here's my 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
)

Here's ~/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)))

When I run lein run, all that happens, after a pause, is the printing of Hello, world! to stdout, and then lein exits. I've independently verified that the (process-files) part of -main isn't getting called. I can run (-main) from the repl and it works properly. What am I doing wrong?

1条回答
倾城 Initia
2楼-- · 2019-08-03 22:55

The map function is lazy, and is not guaranteed process any input unless the corresponding output is accessed. If you are using map for side effects alone, wrap it in dorun. If you also need the result, use doall to force processing of the entire input.

查看更多
登录 后发表回答