|
|
|
|
|
by roenxi
926 days ago
|
|
> My limited understanding of Clojure's HMR is that there aren't n distinct versions of a class/function. It's actually removing the old ones from memory and replacing them. It is almost both. Clojure creates n distinct versions of the function (which are in fact objects and subject to garbage collection). The symbol of the function is rebound (technically this language is wrong) to point to the most recent one. Then, usually, the Java garbage collector deletes the old object. So it is possible (likely under some code styles) that old versions of a function can hang around in a REPL environment if they ended up embedded in a data structure. However, if you make the call by resolving the function's symbol then that will reliably call the most recently def-ed version. For example: (defn poor-style [] 1) (def object
{:fn poor-style
:call (fn [] (poor-style))}) (defn poor-style [] 2) (prn ((:fn object))) ; => 1, calls the old embedded function (prn ((:call object))) ; => 2, calls a function that resolves the symbol, finds the new version. (prn (poor-style)) ;=> 2, just call the new function |
|