Testing bindings for livecoding in Janet
Created on 2021-03-28T02:17:04-05:00
Livecoding in Janet is possible (but not discussed much?)
To accomplish it you have to make sure anything replacable at runtime is stored properly. It must go in a (var) instead of a (def) because you need to be able to (set) it to a new function. Paving over defines by using a new (def) can work but previously minted code will continue to use the now-inaccessible functions or values that were there originally.
Replacing def bindings is allowed but just puts old value out of scope:
(defn boggle [] (pp "potato jacks")) (defn jiggle [] (boggle)) (boggle) (jiggle) (defn boggle [] (pp "jingle jacks")) (boggle) (jiggle)
Replacing var bindings also just puts the old one out of scope:
(var boggle (fn [] (pp "potato jacks"))) (var jiggle (fn [] (boggle))) (boggle) (jiggle) (var boggle (fn [] (pp "jingle jacks"))) (boggle) (jiggle)
Setting an existing var binding will update which function is called:
(var boggle (fn [] (pp "potato jacks"))) (var jiggle (fn [] (boggle))) (boggle) (jiggle) (set boggle (fn [] (pp "jingle jacks"))) (boggle) (jiggle)