Arc Forumnew | comments | leaders | submitlogin
Loading files repeatedly in the repl
6 points by akkartik 5220 days ago | 2 comments
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 file

3. 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))


2 points by akkartik 5219 days ago | link

Addendum to 4: The idiom seems to be (do1 t ..) http://arclanguage.org/item?id=4005

-----

1 point by idoh 5218 days ago | link

Thanks - I'm using 1.

-----