我是 Clojure 的新手,在我已经浪费了太多时间等待 Leiningen 运行我的代码之后,我正试图转向 Cake。虽然 Cake 的持久 JVM 加载速度非常快——它提出了一个更大的问题——但我的函数也是持久的!
为了演示这个问题,我开始了一个蛋糕项目(使用cake new mess-up-with-cake),并写在core.clj:
(ns mess-up-with-cake.core)
(defn main-function[]
  (println "I'm in the main function")
)
(println "I'm in core.clj, not inside in any function") 
这是project.clj:
(defproject mess-up-with-cake "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :dependencies [[clojure "1.2.0"]])
(use 'mess-up-with-cake.core)
(deftask my-task
         (println "I'm in my task")
         (main-function)
)
使用 运行它时cake my-task,我得到:
I'm in core.clj, not inside in any function
I'm in my task
I'm in the main function
这里没有惊喜。
现在,我改成core.clj了这样:
(ns mess-up-with-cake.core)
(defn main-function[]
  (println "I'm in the main function")
  (println "I've made a change in the main function")
)
(println "I'm in core.clj, not inside in any function")
(println "I've made a change outside the main function") 
当我运行它时,我得到
I'm in core.clj, not inside in any function
I've made a change outside the main function
I'm in my task
I'm in the main function 
core.clj显然已重新加载,但我在 main 函数中所做的更改没有打印出来!只有当我停止 JVMcake kill并重新运行它时,我才会得到想要的结果 - 但如果我每次更改函数时都必须重新启动 JVM,我还不如回到 lein...
知道如何强制 cake 重新加载我的函数(并且只有我的函数 - 重新加载整个 Clojure 运行时 + 我正在使用的任何库可能不会比重新启动 JVM 快多少..)?