Closed danielcompton closed 6 years ago
First of all, I want to say that I appreciate your wonderful re-frame
as its heavy user and big fan.
dbgn
is meant to be used wheh I want to see every nested form inside it.
For example
(defn my-fun [a b c]
(dbgn (+ a b c
(->> (range a b)
(map #(* % %))
(filter even?)
(take a)
(reduce +)))))
(my-fun 10 20 100)
I admit that the following evaluated results are a little bit ugly. So I plan not to print the repeated duplicate values by default in the next version of debux.
REPL output:
dbgn: (+ a b c (->> (range (- b a)) (map (fn* [p1__17610#] (* p1__17610# p1_ ... =>
| a =>
| 10
| b =>
| 20
| c =>
| 100
| + =>
| #function[clojure.core/+]
| a =>
| 10
| even? =>
| #function[clojure.core/even?]
| (fn* [p1__17610#] (* p1__17610# p1__17610#)) =>
| #function[four-clojure.core/my-fun/result--8130--auto----17611]
| b =>
| 20
| a =>
| 10
| (- b a) =>
| 10
| (range (- b a)) =>
| (0 1 2 3 4 5 6 7 8 9)
| (map (fn* [p1__17610#] (* p1__17610# p1__17610#)) (range (- b a))) =>
| | p1__17610# =>
| | 0
| | p1__17610# =>
| | 0
| | (* p1__17610# p1__17610#) =>
| | 0
| (0| p1__17610# =>
| | 1
| | p1__17610# =>
| | 1
| | (* p1__17610# p1__17610#) =>
| | 1
| 1| p1__17610# =>
| | 2
| | p1__17610# =>
| | 2
| | (* p1__17610# p1__17610#) =>
| | 4
| 4| p1__17610# =>
| | 3
| | p1__17610# =>
| | 3
| | (* p1__17610# p1__17610#) =>
| | 9
| 9| p1__17610# =>
| | 4
| | p1__17610# =>
| | 4
| | (* p1__17610# p1__17610#) =>
| | 16
| 16| p1__17610# =>
| | 5
| | p1__17610# =>
| | 5
| | (* p1__17610# p1__17610#) =>
| | 25
| 25| p1__17610# =>
| | 6
| | p1__17610# =>
| | 6
| | (* p1__17610# p1__17610#) =>
| | 36
| 36| p1__17610# =>
| | 7
| | p1__17610# =>
| | 7
| | (* p1__17610# p1__17610#) =>
| | 49
| 49| p1__17610# =>
| | 8
| | p1__17610# =>
| | 8
| | (* p1__17610# p1__17610#) =>
| | 64
| 64| p1__17610# =>
| | 9
| | p1__17610# =>
| | 9
| | (* p1__17610# p1__17610#) =>
| | 81
| 81)
| (filter even? (map (fn* [p1__17610#] (* p1__17610# p1__17610#)) (range ... =>
| (0 4 16 36 64)
| (take a (filter even? (map (fn* [p1__17610#] (* p1__17610# p1__17610#) ... =>
| (0 4 16 36 64)
| (reduce + (take a (filter even? (map (fn* [p1__17610#] (* p1__17610# p ... =>
| 120
| (+ a b c (reduce + (take a (filter even? (map (fn* [p1__17610#] (* p1_ ... =>
| 250
However, If I had implemented dbgn
like dbg
in case of ->
or ->>
macro, I would not have seen the values of (- b a)
, and #(* % %)
here. So I gave it up inside dbgn
.
When I want to see dbg->>
effect inside dbgn
, I do it as follows, because dbg
can be placed inside dbgn
or vice versa since the version 0.4.2.
(defn my-fun [a b c]
(dbgn (+ a b c
(dbg (->> (range (- b a))
(map #(* % %))
(filter even?)
(take a)
(reduce +))))))
(my-fun 10 20 100)
REPL output:
dbgn: (+ a b c (dbg (->> (range (- b a)) (map (fn* [p1__16770#] (* p1__16770 ... =>
| a =>
| 10
| b =>
| 20
| c =>
| 100
dbg: (->> (range (- b a)) (map (fn* [p1__16770#] (* p1__16770# p1__16770#)) ... =>
| (range (- b a)) =>
| (0 1 2 3 4 5 6 7 8 9)
| (map (fn* [p1__16770#] (* p1__16770# p1__16770#))) =>
| (0 1 4 9 16 25 36 49 64 81)
| (filter even?) =>
| (0 4 16 36 64)
| (take a) =>
| (0 4 16 36 64)
| (reduce +) =>
| 120
| (+ a b c (dbg (->> (range (- b a)) (map (fn* [p1__16770#] (* p1__16770 ... =>
| 250
In case of let
and comp
, the reason is the same as ->
and ->>
. You can put dbg
in front of let
and comp
whenever you want.
In my conclusion, the main reason why I didn't implement dbgn
like dbg
in case of ->
, ->>
, comp
and let
was the consistency, which is that every nested form should be seen inside dbgn
as much as possible.
This issue is resolved and the related content is added to Mixed use of dbg
and dbgn
in README documentation.
Hi there, firstly thanks heaps for creating this library, it is very useful. I've been looking at the output of
dbg
anddbgn
and wondered if it would be possible fordbgn
to use the special-casing approach indbg
where it wraps->
,->>
,comp
andlet
?I've taken a look through the code and I get the general approach, but wondered if there were some subtleties which meant that the approaches of
dbg
anddbgn
wouldn't work together?