-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.cljc
23 lines (20 loc) · 860 Bytes
/
debug.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(ns ysera.debug
#?(:clj (:require [net.cgrand.macrovich :as macros])
:cljs (:require-macros [net.cgrand.macrovich :as macros]
[ysera.debug :refer [printlet printreturn]])))
(macros/deftime
; from http://brownsofa.org/blog/2014/08/03/debugging-in-clojure-tools/
(defmacro printlet [bindings & body]
`(let [~@(mapcat (fn [[n v]]
(if (or (vector? n) (map? n))
[n v]
[n v '_ `(println (name '~n) ":" ~v)]))
(partition 2 bindings))]
~@body))
(defmacro printreturn
([expression] `(let [result# ~expression]
(println result#)
result#))
([str expression] `(let [result# ~expression]
(println ~str result#)
result#))))