lein run退出而不运行我的所有-main函数 [英] lein run exits without running all of my -main function

查看:113
本文介绍了lein run退出而不运行我的所有-main函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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退出.我已经独立验证了-main(process-files)部分没有被调用.我可以从repl运行(-main),它可以正常工作.我在做什么错了?

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?

推荐答案

map函数是惰性的,除非访问相应的输出,否则不能保证处理任何输入.如果仅将map用于副作用,请将其包裹在dorun中.如果还需要结果,请使用doall强制处理整个输入.

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.

这篇关于lein run退出而不运行我的所有-main函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆