-1

I'm new to clojure and using clojure 1.8, editing with mainly vim. I don't know vim plugins very much.

I have no idea to debug programs using trampoline without plintln because, in my opinion, it's important to know:

  • the order the function calls invoked by trampoline and
  • the arguments to the functions

However debugging by plintln tends to make troubles for maintenance -- it's herder to read because of too many parenthesis.And using too many plintln often makes performance issues. I do not want to switch comment or comment out whenever debugging and release. Are there any good method for debugging for programs using trampoline?

1 Answer 1

0

I found a way to add debugger functions into REPL in a article "break point in clojure". Maybe I should have consider available debuggers from first place...

(defn contextual-eval [ctx expr]
    (eval                                           
        `(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)] 
             ~expr)))
(defmacro local-context []
    (let [symbols (keys &env)]
        (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(defn readr [prompt exit-code]
    (let [input (clojure.main/repl-read prompt exit-code)]
        (if (= input ::tl)
            exit-code
             input)))
;;make a break point
(defmacro break []
  `(clojure.main/repl
    :prompt #(print "debug=> ")
    :read readr
    :eval (partial contextual-eval (local-context))))


Usage:

(defn div [n d] (break) (int (/ n d)))
(div 10 0)
debug=> n
10
debug=> d
0
debug=> (local-context)
{n 10, d 0}
debug=> ::tl
ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:156)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.