Endless Parentheses

Concise ramblings on Emacs productivity.

Support on Gratipay
profile for Malabarba on Stack Exchange

Conditional breakpoints in the CIDER Debugger

CIDER 0.11.0 has been out for less than week and already the snapshots are getting new features. This one comes from a gentleman called Chris Perkins. It provides an easy way to automatically skip some breakpoints during evaluation, and it even comes with 300 brand new lines of tests.

The feature is very straightforward, and is already available on the snapshots of 0.12.0. You’ve always been able to debug functions by adding a #dbg in before it and then reevaluating its definition.

#dbg
(defn buggy-function []
  (for [i (range 3000)]
    (some (kinda complicated)
          code (logic) i)))

However, if you’re trying to debug a problem that only happens somewhere around i = 1000, then you’re going to have to step through the body of that for one thousand times before getting to where you need.

This new feature lets you specify a condition, and the debugger will automatically skip all breakpoints as long as that condition is false. You specify it via the :break/when metadata. In the above example, that would be something like this.

#dbg
(defn buggy-function []
  (for [i (range 3000)]
    ^{:break/when (> i 1000)}
    (some (kinda complicated)
          code (logic) i)))

Thus, everything inside the (some ...) form would be skipped as long as i ≤ 1000.

The debugger’s inner workings are not what I’d call simple, so it makes me happy to know I’ve made the code legible enough for people to understand without my help. Of course, it certainly helped that Chris is no average fellow. Did I mention he even wrote a DSL for the new tests?

Tags: debugging, clojure, emacs

Support on Gratipay
comments powered by Disqus