如何在编辑时使Clojure程序热交换

时间:2016-04-25 08:30:54

标签: clojure

我看过this exciting video。看起来非常有前途的工具在运行时编辑程序,但是当我在启动后尝试编辑例如this program时,它什么都没改变。如何实现这样的功能。 它有任何必要的图书馆。

1 个答案:

答案 0 :(得分:2)

Yes, for certain environments there are are ready to use plugins and libraries which do the reloading for you. Like figwheel for web and test-refresh for tests / simple scripts and others.

If you have some special environment, where a ready to use solution does not fit, you could build something on you're own. For example by running (use my-namespace :reload-all) periodically / when a file changes.

A abstract example for 'poor mans' reload implementation:

(defn game-loop [] 
   (while true 
         ; If a file changes, we want to reload that code
         (when (any-file-changed?)
              (use 'my-game.main :reload-all)
         )
         (my-game.main/tick)  ; Call the game tick every frame
    )
)