Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My favourite method is a liberal sprinkling of <code>println</code>s all over the code... <strong>Turning them on and off is easy</strong> thanks to the <code>#_</code> reader macro (which makes the reader read in the following form, then pretend it's never seen it). Or you could use a macro expanding either to a passed-in body or <code>nil</code> depending on the value of some special variable, say <code>*debug*</code>:</p> <pre><code>(defmacro debug-do [&amp; body] (when *debug* `(do ~@body))) </code></pre> <p>With a <code>(def *debug* false)</code> in there, this will expand to <code>nil</code>. With <code>true</code>, it'll expand to <code>body</code> wrapped in a <code>do</code>.</p> <hr> <p>The accepted answer to this SO question: <strong><a href="https://stackoverflow.com/questions/2022911/idiomatic-clojure-for-progress-reporting">Idiomatic Clojure for progress reporting?</a></strong> is very helpful when debugging sequence operations.</p> <hr> <p>Then there's something which is <strong>currently incompatible with swank-clojure</strong>'s REPL, but is too good not to mention: <strong><code>debug-repl</code></strong>. You can use it in a standalone REPL, which is easy to get e.g. with Leiningen (<code>lein repl</code>); and if you're launching your programme from the command line, then it's going to bring its own REPL up right in your terminal. The idea is that you can drop the <code>debug-repl</code> macro in anywhere you like and have it bring up its own REPL when the programme's execution reaches that point, with all locals in scope etc. A couple of relevant links: <a href="http://georgejahad.com/clojure/debug-repl.html" rel="nofollow noreferrer">The Clojure debug-repl</a>, <a href="http://georgejahad.com/clojure/debug-repl-macros.html" rel="nofollow noreferrer">Clojure debug-repl tricks</a>, <a href="http://groups.google.com/group/clojure/browse_thread/thread/8d77ad0da8d190c8/e39b59fd19cc5675" rel="nofollow noreferrer">how 'bout a debug-repl</a> (on the Clojure Google group), <a href="http://clojars.org/org.clojars.gjahad/debug-repl" rel="nofollow noreferrer">debug-repl on Clojars</a>.</p> <hr> <p>swank-clojure does an adequate job of making SLIME's built-in debugger useful when working with Clojure code -- note how the irrelevant bits of the stacktrace are greyed out so it's easy to find the actual problem in the code being debugged. One thing to keep in mind is that anonymous functions without "name tags" appear in the stacktrace with basically no useful information attached to them; when a "name tag" is added, it does appear in the stacktrace and all is well again:</p> <pre><code>(fn [&amp; args] ...) vs. (fn tag [&amp; args] ...) example stacktrace entries: 1: user$eval__3130$fn__3131.invoke(NO_SOURCE_FILE:1) vs. ^^ 1: user$eval__3138$tag__3139.invoke(NO_SOURCE_FILE:1) ^^^ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload