Skip to content

Instantly share code, notes, and snippets.

@olivergeorge
Last active February 19, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivergeorge/a58e9176846f9c109d004ce00cfe4fae to your computer and use it in GitHub Desktop.
Save olivergeorge/a58e9176846f9c109d004ce00cfe4fae to your computer and use it in GitHub Desktop.
Random thoughts on clojurescript debugging

This strikes me as a handy debugging pattern:

(defonce dbg-db (atom {}))

(defn log [k v]
  (swap! dbg-db update-in [k] conj v)
  (js/console.log k v)
  v)

You can sprinkle log statements in your code to check values (basically js/console.log but returns the value).

The 'innovation' is you can go back and play with the data after execution. Just pop the key you used when logging.

If you turned log into a macro you should be able to capture more context:

  • local vars via &env
  • file, line, column info from &form

Extrapolating further, if s/instrument evolved into a general use technique for hooking into execution then it might be useful for things like breakpoints, stack traces etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment