When debugging I find myself repeatedly loading files into the repl. Here are a few helpers to smooth the rough edges off that use-case. 1. Reduce keystrokes to reload. (def l(f)
(load:+ stringify.f ".arc"))
; stringify = coerce _ 'string
arc> l!server ; => (load "server.arc")
I only ever use this on the repl.2. Don't lose global state when reloading a file. (mac init args
`(unless (bound ',(car args))
(= ,@args)))
I replace top-level = with init within the file3. Don't lose closure state when reloading a file. (mac ifcall(var)
`(if (bound ',var)
(,var)))
; Example usage within a file: server-thread* doesn't lose
; its value across file reloads
(let server-thread* (ifcall server-thread)
(def start-server((o port 8080))
(stop-server)
(= server-thread* (new-thread (fn() (asv port)))))
(def stop-server()
(if server-thread* (kill-thread server-thread*)))
(def server-thread()
server-thread*))
4. Don't accidentally print a huge data structure to screen for several minutes when you only care about side-effects arc> (no:each (k v) very-large-table (do-something))
|