4 ms·
> If somebody knows other languages/systems that do let me know. Clojure can do this via namespace live reload. ClojureScript is already doing this inside figw
by dig1 6y ago
> If somebody knows other languages/systems that do let me know.
Clojure can do this via namespace live reload. ClojureScript is already doing this inside figwheel [1] environment. CommonLisp had this since dawn of time. Kawa [2] can do it, but because it aggressively optimize the code, you need to be careful. Racket can do it as well [3].
[1] https://github.com/bhauman/lein-figwheel https://github.com/bhauman/lein-figwheel
[2] https://www.gnu.org/software/kawa/ https://www.gnu.org/software/kawa/
[3] https://github.com/tonyg/racket-reloadable/tree/master#readme https://github.com/tonyg/racket-reloadable/tree/master#readm...
EDIT: added Kawa and Racket.
- dmux 6y agoTcl as well.
- em-bee 6y agoi believe smalltalk can do this as well. there are also lesser known languages such as pike. although pike doesn't do hotswapping of actual objects but only allows the hotswapping of the compiled classes used to instantiate new objects. this works well enough on webservers where new objects are created for every request, and only live as long as the request is processed. there is a platform called open-steam that emulates hotswapping by using proxy objects. when i reference an object, i actually get a proxy, that then references the real object. when i update the code, then the proxy gets updated to the new real object, and for me it looks like the object i am referencing has been hotswapped.
- rrdharan 6y agoJava with DCEVM or OSGi. This was originally a big OSGi selling point if I recall correctly though I’ve never seen it successfully implemented - though maybe in the Eclipse IDE? Anyway it’s a very well studied and covered topic in the Java ecosystem as I understand it... http://ssw.jku.at/dcevm/ http://ssw.jku.at/dcevm/ http://blog.ruwan.org/2012/12/dynamic-hot-swap-environment-inside.html http://blog.ruwan.org/2012/12/dynamic-hot-swap-environment-i... https://www.jrebel.com/blog/java-hotswap-guide https://www.jrebel.com/blog/java-hotswap-guide
- bjourne 6y agoThe languages you mention can't update data in flight, which is something Erlang can. Suppose you have the following code running in a thread: def print_name(d): print(d['name']) d = {'name' : 'hello'} while True: print_name(d) Now you hot hot-swap it while the while-loop is running: def print_name(d): print('hello', d['first_name']) d = {'first_name' : 'there'} while True: print_name(d) Erlang can do this. No other language that I'm aware of can.
- dig1 6y agoClojure has all sorts of facilities to do that (atoms, agents or refs). You can even listen for changes [1] and compare old and new values. [1] https://clojuredocs.org/clojure.core/add-watch https://clojuredocs.org/clojure.core/add-watch
- bjourne 6y agoInteresting, I didn't know that. I don't understand how the function you link to can be used to accomplish that. Can you give me an example?
- dig1 6y agoSure; here is example with atom: ;; define a map (def myvar (atom {:foo 1})) ;; add watcher for 'myvar'; it will call anonymous ;; function and set old-state with previous value and new-state ;; with new value, when 'myvar' was changed (add-watch myvar :dummy (fn [_ _ old-state new-state] (println "changed! - old: " old-state " new: " new-state))) ;; Run separate thread and and update :foo value to 2, after 6 seconds. ;; No scheduling is necessary, this is so it can be evaluated in REPL easily. (future (Thread/sleep 6000) (swap! myvar assoc :foo 2)) ;; Infinite loop. Sleep for 0.5 seconds just for printing purposes. (loop [] (println @myvar) (Thread/sleep 500) (recur)) and you will see output like this: {:foo 1} {:foo 1} {:foo 1} {:foo 1} {:foo 1} {:foo 1} {:foo 1} {:foo 1} changed! - old: {:foo 1} new: {:foo 2} {:foo 2} {:foo 2} {:foo 2} {:foo 2} {:foo 2} {:foo 2}