Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
philoskim committed Aug 9, 2021
1 parent 28ed9c1 commit d4ef567
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 50 deletions.
126 changes: 106 additions & 20 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ To include `debux` in your project for development, simply add the following to

[source]
....
[philoskim/debux "0.7.9"]
[philoskim/debux "0.8.0"]
....

and this to your *production* dependencies.

[source]
....
[philoskim/debux-stubs "0.7.9"]
[philoskim/debux-stubs "0.8.0"]
....


Expand All @@ -65,7 +65,9 @@ and this to your *production* dependencies.
NOTE: You can see _All change logs since v0.3.0_
https://github.com/philoskim/debux/tree/master/doc/change-logs.adoc[here].

* v0.7.10
* v0.8.0
** `dbgt` and `clogt` macros for debugging transducers added. See the details
<<dbgt, here>>.
** `set-debug-level!` removed. Instead, use `with-level` macro. See the details
<<with-level, here>>.
Expand Down Expand Up @@ -2221,28 +2223,111 @@ dbg: (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) <thread
| "X"
----

[[dbgt]]
## `dbgt` examples

NOTE: The features of `clogt` are almost the same as those of `dbgt`.

`dbgt` and `clogt` macros are for debugging transducers.

Special thanks to
link:https://github.com/green-coder/transducer-exercises/blob/master/solution/debug.clj[Vincent
Cantin] for the idea and inspiration for my writing these macros.


### Debugging a single transducer

[source]
.Example
....
(transduce (dbgt (filter odd?))
conj (range 5))
....

[listing]
.REPL output
----
{:ns examples.lab, :line 5}
dbgt: (filter odd?)
|> 0
|< []
|> 1
|< [1]
|> 2
|< [1]
|> 3
|< [1 3]
|> 4
|< [1 3]
----

### .Debugging composed transducers

[source]
.Example
....
(transduce (dbgt (comp (map inc) (filter odd?)))
conj (range 5))
....

[listing]
.REPL output
----
{:ns examples.lab, :line 8}
dbgt: (comp (map inc) (filter odd?))
|> 0
||> 1
||< [1]
|< [1]
|> 1
||> 2
||< [1]
|< [1]
|> 2
||> 3
||< [1 3]
|< [1 3]
|> 3
||> 4
||< [1 3]
|< [1 3]
|> 4
||> 5
||< [1 3 5]
|< [1 3 5]
----



## Various options

* The various options can be added and combined in any order after the form.

[cols="^1m,^1m,^1m,^1m,^1m,^1m", options="header"]
[cols="^1m,^1m,^1m,^1m,^1m,^1m,^1m,^1m", options="header"]
.*debux* macro options
|===

| Optio ns | dbg | dbgn | clog | clogn | break
| Optio ns | dbg | dbgn | clog | clogn | dbgt | clogt | break

| string | O | O | O | O | O
| :msg or :m | O | O | O | O | X
| number | O | O | O | O | X
| :if | O | O | O | O | O
| :locals or :l | O | O | O | O | X
| :print or :p | O | X | O | X | X
| :dup | X | 0 | X | 0 | X
| :level | O | O | O | O | X
| :style or :s | X | X | O | O | X
| :once or :o | X | X | O | X | X
| :js | X | X | O | O | X
| string | O | O | O | O | O | O | O
| :msg or :m | O | O | O | O | O | O | X
| number | O | O | O | O | X | X | X
| :if | O | O | O | O | O | O | O
| :locals or :l | O | O | O | O | X | X | X
| :print or :p | O | X | O | X | X | X | X
| :dup | X | 0 | X | 0 | X | X | X
| :level | O | O | O | O | O | O | X
| :style or :s | X | X | O | O | X | O | X
| :once or :o | X | X | O | X | X | X | X
| :js | X | X | O | O | X | X | X

|===

Expand Down Expand Up @@ -2988,10 +3073,9 @@ image::clog-js.png[title=":js option example", width=800]


[[tagged-literals]]
## Tagged literals: `#d/dbg`, `#d/dbgn`, `#d/clog`, `#d/clogn`
## Tagged literals: `#d/dbg`, `#d/dbgn`, `#d/dbgt`,`#d/clog`, `#d/clogn`, `#d/clogt`

If you don't use the above options at all, you can use the tagged literals: `#d/dbg`,
`#d/dbgn`, `#d/clog`, `#d/clogn`. They behave exactly in the same way as their
If you don't use the above options at all, you can use the tagged literals: `#d/dbg`, `#d/dbgn`, `#d/dbgt`,`#d/clog`, `#d/clogn`, `#d/clogt`. They behave exactly in the same way as their
counterparts `dbg`, `dbgn`, `clog`, `clogn`. So in the _no options_ case, you don't have
to wrap the form by the parentheses any more, if you want.

Expand Down Expand Up @@ -3373,11 +3457,13 @@ debux macro names or turn off the tagged literals by appending `pass:q[_]` after

| dbg | dbg_ | #d/dbg | #_d/dbg
| dbgn | dbgn_ | #d/dbgn | #_d/dbgn
| dbgt | dbgt_ | #d/dbgt | #_d/dbgt
| dbg-prn | dbg-prn_ | |
| dbg-last | dbg-last_ | |

| clog | clog_ | #d/clog | #_d/clog
| clogn | clogn_ | #d/clogn | #_d/clogn
| clogt | clogt_ | #d/clogt | #_d/clogt
| clog-last | clog-last_ | |

| break | break_ | |
Expand Down Expand Up @@ -3525,7 +3611,7 @@ an example about running the link:https://github.com/bhauman/lein-figwheel[figwh
(defproject examples "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.10.238"]
[philoskim/debux "0.7.9"]]
[philoskim/debux "0.8.0"]]
:plugins [[lein-cljsbuild "1.1.6"]
[lein-figwheel "0.5.10"]]
:source-paths ["src/clj"]
Expand Down
5 changes: 3 additions & 2 deletions doc/change-logs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
:source-highlighter: coderay
:sectnums:

* v0.7.10
** `set-debug-level!` is removed. Instead, use `with-level` macro.
* v0.8.0
** `dbgt` and `clogt` macros for debugging transducers added.
** `set-debug-level!` removed. Instead, use `with-level` macro.
* v0.7.9
** `set-debug-level!` added.
Expand Down
2 changes: 1 addition & 1 deletion examples/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.10.238"]
[org.clojure/core.async "0.3.465"]
[philoskim/debux "0.7.9"]]
[philoskim/debux "0.8.0"]]
:plugins [[lein-cljsbuild "1.1.7"]
[lein-figwheel "0.5.18"]]
:source-paths ["src/clj" "src/cljc"]
Expand Down
12 changes: 6 additions & 6 deletions examples/src/clj/examples/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
;; You should require dynamically the namespaces that you want to laod
;; if you want to use set-ns-blacklist! or set-ns-whitelist!.

;(require 'examples.common)
;(require 'examples.dbg)
;(require 'examples.dbgn)
;(require 'examples.options)
;(require 'examples.etc)
(require 'examples.common)
(require 'examples.dbg)
(require 'examples.dbgn)
(require 'examples.options)
(require 'examples.etc)
;(require 'examples.demo)
(require 'examples.lab)
;(require 'examples.lab)
)
8 changes: 8 additions & 0 deletions examples/src/clj/examples/etc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
(set-line-bullet! "|")


;;; debug level
;; The default debug level is 0.
(dbg (+ 10 20))
(dbg (+ 10 20 3) :level 3)
Expand All @@ -85,3 +86,10 @@
(with-level 0
(dbg (* 10 2))))


;;; dbgt for transducers
(transduce (dbgt (filter odd?))
conj (range 10))

(transduce (dbgt (comp (map inc) (filter odd?)))
conj (range 5))
6 changes: 0 additions & 6 deletions examples/src/clj/examples/lab.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
(ns examples.lab)

(use 'debux.core)

(transduce (dbgt (filter odd?))
conj (range 5))

(transduce (dbgt (comp (map inc) (filter odd?)))
conj (range 5))
16 changes: 8 additions & 8 deletions examples/src/cljs/examples/core.cljs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(ns examples.core
(:require ;examples.common
;examples.clogn
;examples.clog
;examples.dbgn
;examples.dbg
;examples.options
;examples.etc
(:require examples.common
examples.clogn
examples.clog
examples.dbgn
examples.dbg
examples.options
examples.etc
;examples.demo
examples.lab
;examples.lab
))

8 changes: 4 additions & 4 deletions examples/src/cljs/examples/demo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@


;;; break examples
(break)
(break "hello world")
(break :if (> 10 20) "this will not be printed")
(break :if (< 10 20) "10 is less than 20")
;;(break)
;;(break "hello world")
;;(break :if (> 10 20) "this will not be printed")
;;(break :if (< 10 20) "10 is less than 20")

(defn my-fun2
[a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]]
Expand Down
17 changes: 17 additions & 0 deletions examples/src/cljs/examples/etc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
clog_ clogn_ clog-last_
dbg dbgn dbg-last
dbg_ dbgn_ dbg-last_
dbgt dbgt_ clogt clogt_
break break_ with-level]]))

;; tagged literals
Expand Down Expand Up @@ -100,6 +101,7 @@
(d/set-line-bullet! "|")


;;; debug level
;; The default debug level is 0.
(dbg (+ 10 20))
(dbg (+ 10 20 3) :level 3)
Expand Down Expand Up @@ -137,3 +139,18 @@

(with-level 0
(clog (* 10 2))))


;;; dbgt/dlogt for transducers
(transduce (dbgt (filter even?))
conj (range 5))

(transduce (dbgt (comp (map inc) (filter even?)))
conj (range 5))


(transduce (clogt (filter even?) :js)
conj (range 5))

(transduce (clogt (comp (map inc) (filter even?)))
conj (range 5))
2 changes: 1 addition & 1 deletion examples/src/cljs/examples/lab.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
conj (range 5))


(transduce (clogt (filter even?))
(transduce (clogt (filter even?) :js)
conj (range 5))

(transduce (clogt (comp (map inc) (filter even?)))
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject philoskim/debux "0.7.9"
(defproject philoskim/debux "0.8.0"
:description "A trace-based debugging library for Clojure and ClojureScript"
:url "https://github.com/philoskim/debux"
:license {:name "Eclipse Public License - v 1.0"
Expand Down
4 changes: 3 additions & 1 deletion src/data_readers.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{d/dbg debux.core/dbg-tag
d/dbgn debux.core/dbgn-tag
d/dbgt debux.core/dbgt-tag
d/clog debux.cs.core/clog-tag
d/clogn debux.cs.core/clogn-tag}
d/clogn debux.cs.core/clogn-tag
d/clogt debux.cs.core/clogt-tag}
16 changes: 16 additions & 0 deletions src/debux/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,32 @@
(dbgn/dbgn ~form {} ~(ut/parse-opts opts)))
~form) )))

(defmacro dbgt* [form meta]
(let [ns (str *ns*)
line (:line meta)
opts [:ns ns :line line]]
(if (ut/cljs-env? &env)
`(cs/dbgt* ~form ~meta)
`(if (ut/debug-enabled? ~ns)
(locking locking*
(dbgt/dbgt ~form {} ~(ut/parse-opts opts)))
~form) )))

(defn dbg-tag [form]
`(dbg* ~form ~(meta form)))

(defn dbgn-tag [form]
`(dbgn* ~form ~(meta form)))

(defn dbgt-tag [form]
`(dbgt* ~form ~(meta form)))


;;; turn-off versions
(defmacro dbg_ [form & opts] form)
(defmacro dbgn_ [form & opts] form)
(defmacro dbgt_ [form & opts] form)

(defn dbg-prn_ [& args])
(defmacro dbg-last_ [& args] (last args))

Expand Down

0 comments on commit d4ef567

Please sign in to comment.