Debug without a debugger






cycognito



clojure logo

Agenda







Leverage homoiconicity and immutability to empower your developing experience

A buggy function

(defn foo [a b]
  (let [x (/ a b)
        y (+ a b)]
    (+ x y)))


(foo 2 3)

Old well known print

(defn foo [a b]
  (let [x (/ a b)
        y (+ a b)]
    (println "x: " x)
    (println "y: " y)
    (+ x y)))


(foo 2 3)

dbg macro

(defn foo [a b]
  (+ (dbg (* a b))
     (/ (dbg b) 3)))


(foo 12 2)

☕ How is it related to homoiconicity?

(defmacro dbg[x]
  (when *assert*
    `(let [x# ~x]
       (println (str '~x ": ") x#)
       x#)))

def like crazy

(defn foo [a b]
  (let [x (/ a b)
        y (+ a b)]
    (def x x)
    (def y y)
    (+ x y)))


(foo 2 3)
(+ x y)

☕ How is it related to immutability?

Welcome scope-capture

Demo on the IDE

Homeworks

  • Use the dbg macro

  • Add sc.api to your profile.clj

  • Play with sc.api