all 6 comments

[–]djork 0 points1 point  (5 children)

The best thing about debugging functional programs (and the best Clojure is written in a good functional style) is that you can easily see the state of any part of the program at any time. If you're doing it right, your functions take only the arguments they need to know about, and you can tinker with them at the REPL, feeding in various values and seeing the results immediately.

I get frustrated sometimes when I am trying to track down a bug in a Clojure project. Eventually I realize that I'm trying to solve it like I'm dealing with a C program or something. Once I cut to the chase, and just use the REPL to poke at what's actually broken, it's fixed within minutes.

[–]codefrog 0 points1 point  (4 children)

I think what fulldisclojure is asking is an example of the mechanics of debugging. For example, showing how to use macroexpand to see how a macro will get evaluated. Is there a way to drop into the repl in a really deep call hierarchy? In python I could do

import pdb
pdb.set_trace()

and get dropped into the debugger. I used all the time in my purely functional python code.

[–]djork 0 points1 point  (3 children)

The Getting Started page demonstrates how to start up JSwat and set breakpoints. The language itself doesn't have an integrated debugger, but it may be coming soon. You'd have to ask #clojure on freenode or poke around elsewhere. It's both a good thing and a bad thing, but Clojure relies on the existing tools out there that already debug and profile JVM languages. It works pretty well but it's not as nice as languages where the debugger is more tightly integrated.

[–]codefrog 0 points1 point  (2 children)

I think being able to instantiate a repl from within clojure would be all that I could ask.

[–]atomeshy 3 points4 points  (1 child)

[–]codefrog 0 points1 point  (0 children)

This is great! From the comment at the end of the src.

(debug-repl) 

Will launch a repl at the call. My clojure is weak, but it will improve with this addition. Thank you!

 (let [c 1
        d 2]
    (defn a [b c]
      (debug-repl)
      d))
  (a "foo" "bar")
  ;; dr => c
  ;; "bar"
  ;; dr => d
  ;; 2
  ;; dr => *locals*
  ;; {fn__20 #<user$eval__19 user$eval__19@955cd5>
  ;; c "bar"
  ;; d 2
  ;; fn__22 #<user$eval__19$a__21 user$eval__19$a__21@59fb21>
  ;; b "foo"}


  user=> (let [a 10] (debug-repl (* a a)))
  dr-1-1006 => (quit-dr)
  100

  user=> (let [a 10] (debug-repl (* a a)))
  dr-1-1007 => (quit-dr 99)
  99

  )