diff --git a/.gitignore b/.gitignore index af2137f..f801265 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ /out .nrepl-history +/example/target +/example/resources/public/js + *~ *# .#* diff --git a/README.adoc b/README.adoc index c05216b..d27e598 100644 --- a/README.adoc +++ b/README.adoc @@ -1,10 +1,12 @@ -# debux +# Debux :source-language: clojure :source-highlighter: coderay :sectnums: :imagesdir: ./doc/img -Debux is a simple but useful library for debugging Clojure and ClojureScript. I wrote this library to debug my own Clojure(Script) code and to analyze other developer's Clojure(Script) code. +*Debux* is a simple but useful library for debugging Clojure and ClojureScript. I wrote +this library to debug my own Clojure(Script) code and to analyze other developer's +one. ## Prerequisites @@ -20,7 +22,7 @@ To include *debux* in your project, simply add the following to your *project.cl [source] .... -[philoskim/debux "0.2.0"] +[philoskim/debux "0.2.1"] .... @@ -35,21 +37,31 @@ In Clojure, the following line has to be included in your file to use *debux* li (use 'debux.core) .... -In ClojureScript, the following `(:require ...)` line has to be included in your file to use *debux* library. +In ClojureScript, the following `(:require pass:q[...])` line has to be included in your +file to use *debux* library. [source] .... (ns example.core - (:require [debux.cs.core :refer-macros [clog dbg]])) + (:require [debux.cs.core :refer-macros [clog dbg break]])) .... + - +## Change Logs + +* Version 0.2.1: +** Fixed: An error fixed when using `(clog (pass:q[->> .....]))` +** Fixed: An error fixed when using `(dbg (let [[a *&* b] [10 20 30]] pass:q[......]))` +** Added: `break` usage + + ## New features added in version 0.2.0 ### Debugging thread macro `pass:[->]` or `pass:[->>]` -When debugging the thread-first macro `pass:[->]` or thread-last macro `pass:[->>]`, debux prints every expression in the thread macros. +When debugging the thread-first macro `pass:[->]` or thread-last macro `pass:[->>]`, `dbg` +prints every expression in the thread macros. This is an example of thread-first macro `pass:[->]`. @@ -213,23 +225,26 @@ When debugging `let` form, [source] .... -(dbg (let [c (+ 1 2) - [d e] [5 6]] - (-> (+ d e) (- c)))) -; => 8 +(dbg (let [a (take 5 (range)) + {:keys [b c d] :or {d 10 b 20 c 30}} {:c 50 :d 100} + [e f g & h] ["a" "b" "c" "d" "e"]] + [a b c d e f g h])) +; => [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] .... each binding will be printed. .REPL output: .... -dbg: (let [c (+ 1 2) [d e] [5 6]] ...) - c => - 3 - [d e] => - [5 6] +dbg: (let [a (take 5 (range)) {:keys [b c d], :or {d 10, b 20, c 30}} {:c 50, :d 100} [e f g & h] ["a" "b" "c" "d" "e"]] ...) + a => + (0 1 2 3 4) + {:keys [b c d], :or {d 10, b 20, c 30}} => + {:keys [20 50 100], :or {100 10, 20 20, 50 30}} + [e f g & h] => + ["a" "b" "c" & ("d" "e")] => - 8 + [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] .... When debugging `comp` form, @@ -313,10 +328,12 @@ Sometimes you need to see several forms evaluated. To do so, a literal vector fo [source] .... -(let [a (take 5 (range)) - {:keys [b c d] :or {d 10 b 20 c 30}} {:c 50 :d 100} - [e f g & h] ["a" "b" "c" "d" "e"]] + +(defn my-fun + [a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]] (dbg [a b c d e f g h])) + +(my-fun (take 5 (range)) {:c 50 :d 100} ["a" "b" "c" "d" "e"]) ; => [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] .... @@ -487,10 +504,14 @@ dbg: i => ## Usage in ClojureScript on Browser Console -You can use `dbg` or `clog` macro in REPL window like *weasel* in ClojureScript. However, you should use `clog` instead of `dbg`, because `clog` macro uses the `console.log` fuction of browser's developer tools to style the form. The evaluated result of `dbg` macro will go to the REPL window, and that of `clog` macro will go to the browser's console. +You can use `dbg` or `clog` macro in REPL window like +link:https://github.com/tomjakubowski/weasel[weasel] in ClojureScript. However, you should +use `clog` instead of `dbg`, because `clog` macro uses the `console.log` fuction of +browser's developer tools to style the form. The evaluated result of `dbg` macro will go +to the REPL window, and that of `clog` macro will go to the browser's console. -The following `(:require ...)` line has to be included in your file to use *debux* library in ClojureScript. +The following `(:require pass:q[...])` line has to be included in your file to use *debux* library in ClojureScript. [source] @@ -534,6 +555,16 @@ You can style the form, using the following predefined keywords. (clog (+ 10 20) :style :debug "debug style") (clog (+ 10 20) "debug style is default") .... + +Or in brief + +.... +(clog (+ 10 20) :s :e "error style") +(clog (+ 10 20) :s :w "warn style") +(clog (+ 10 20) :s :i "info style") +(clog (+ 10 20) :s :d "debug style") +(clog (+ 10 20) "debug style is default") +.... image::clog-2.png[] @@ -588,7 +619,10 @@ If you add `:once` (or `:o` in brief) option after the form, the same evaluated image::clog-4.png[] +* Notice that `(:once mode)` string is appended after the evaluated result to indicate + `once` mode. + ### `:js` option If `:js` option is added after the form, the JavaScript object will be printed as well, so you can inspect the internal structures of ClojureScript data types. @@ -600,30 +634,61 @@ If `:js` option is added after the form, the JavaScript object will be printed a image::clog-5.png[] +## `break` + +You can use `break` to set the breakpoint in the sourc code like this. After that you can +inspect the callstack, locals, etc. in the browser's DevTool window. + +[source] +.... +(defn my-fun2 + [a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]] + (break) + (clog [a b c d e f g h])) + +(my-fun2 (take 5 (range)) {:c 50 :d 100} ["a" "b" "c" "d" "e"]) +.... + +image:break.png[] + + +When using `break`, you can `:if expression` like this. + +[source] +.... +(defn my-fun3 [] + (let [a 10 + b 20] + (dotimes [i 1000] + (break :if (= i 999))))) + +(my-fun3) +.... + +image:break-if.png[] + + ## Usage in ClojureScript on Browser REPL -You can use both `dbg` and `clog` macros on the browser REPL like *weasel*. The following is an example about runing the browser REPL *weasel*. +You can use both `dbg` and `clog` macros on the browser REPL. The following is an example about +runing the link:https://github.com/bhauman/lein-figwheel[Figwheel]. [source] .... -;; project.clj -(defproject example "0.2.0-SNAPSHOT" +(defproject example "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.8.0"] - [org.clojure/clojurescript "1.7.228"] - [com.cemerick/piggieback "0.2.1"] - [weasel "0.7.0"] - [philoskim/debux "0.2.0"]] - :plugins [[lein-cljsbuild "1.0.5"] - [lein-figwheel "0.3.7"]] + [org.clojure/clojurescript "1.8.51"] + [philoskim/debux "0.2.1"]] + :plugins [[lein-cljsbuild "1.1.3"] + [lein-figwheel "0.5.1"]] :source-paths ["src/clj"] :clean-targets ^{:protect false} ["resources/public/js/app.js" "resources/public/js/app.js.map"] - :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} :cljsbuild {:builds [{:id "dev" :source-paths ["src/cljs"] :figwheel true - :compiler {:main "example.brepl" + :compiler {:main example.core :asset-path "js/out" :output-to "resources/public/js/app.js" :output-dir "resources/public/js/out" @@ -632,38 +697,55 @@ You can use both `dbg` and `clog` macros on the browser REPL like *weasel*. The .... -[source] -.... -;; example/brepl.cljs -(ns example.brepl - (:require [cljs.debux :refer-macros [dbg clog break]] - [weasel.repl :as ws-repl] )) - -(ws-repl/connect "ws://localhost:9001") -.... - -Aftr that, you have to evaluate the following forms in your REPL window to run the browser REPL *weasel*. +ANd then run figwheel like this on terminal window. [listing] ---- -user> (require '[weasel.repl.websocket :as ws] - '[cemerick.piggieback :as pback]) -nil - -user> (pback/cljs-repl (ws/repl-env :port 9001)) -<< started Weasel server on ws://127.0.0.1:9001 >> -<< waiting for client to connect ... +$ lein figwheel +Figwheel: Validating the configuration found in project.clj + +Figwheel: Configuration Valid. Starting Figwheel ... +Figwheel: Starting server at http://localhost:3449 +Port 3449 is already being used. Are you running another Figwheel instance? If you want to run two Figwheel instances add a new :server-port (i.e. :server-port 3450) to Figwheel's config options in your project.clj +Figwheel: Watching build - dev +Compiling "resources/public/js/app.js" from ["src/cljs"]... +Successfully compiled "resources/public/js/app.js" in 2.257 seconds. +Launching ClojureScript REPL for build: dev +Figwheel Controls: + (stop-autobuild) ;; stops Figwheel autobuilder + (start-autobuild [id ...]) ;; starts autobuilder focused on optional ids + (switch-to-build id ...) ;; switches autobuilder to different build + (reset-autobuild) ;; stops, cleans, and starts autobuilder + (reload-config) ;; reloads build config and resets autobuild + (build-once [id ...]) ;; builds source one time + (clean-builds [id ..]) ;; deletes compiled cljs target files + (print-config [id ...]) ;; prints out build configurations + (fig-status) ;; displays current state of system + Switch REPL build focus: + :cljs/quit ;; allows you to switch REPL to another build + Docs: (doc function-name-here) + Exit: Control+C or :cljs/quit + Results: Stored in vars *1, *2, *3, *e holds last exception object +Prompt will show when Figwheel connects to your application ---- -Refresh your browser's page, and then you will see the following in your REPL window. +After that, connect to `http://localhost:3449` on your borwser. [listing] ---- -<< waiting for client to connect ... connected! >> To quit, type: :cljs/quit -cljs.user> ----- +cljs.user=> (require '[debux.cs.core :refer-macros [clog dbg break]]) +nil + +cljs.user=> (dbg (+ 1 2)) + +dbg: (+ 1 2) => + 3 +3 +cljs.user=> +---- + Now you can do anything in this REPL as in the Clojure REPL. When you evaluate `dbg` macro in your ClojureScript source code, the result will go to the REPL window and when you evaluate `clog` macro in your ClojureScript source code, the result will go to your browser's console window. diff --git a/build.boot b/build.boot index d3c1010..edd0e4d 100644 --- a/build.boot +++ b/build.boot @@ -1,15 +1,15 @@ (set-env! :project 'philoskim/debux - :version "0.2.0" + :version "0.2.1" :source-paths #{"src"} :resource-paths #{"src" "html"} - :dependencies '[[org.clojure/clojure "1.8.0"] - [org.clojure/clojurescript "1.7.228"] + :dependencies '[[org.clojure/clojure "1.8.0" :scope "provided"] + [org.clojure/clojurescript "1.8.51" :scope "provided"] [adzerk/boot-cljs "1.7.228-1" :scope "test"] ; CLJS compiler - [adzerk/boot-reload "0.4.4" :scope "test"] ; live reload + [adzerk/boot-reload "0.4.6" :scope "test"] ; live reload [adzerk/boot-cljs-repl "0.3.0" :scope "test"] ; add bREPL [com.cemerick/piggieback "0.2.1" :scope "test"] ; needed by bREPL [weasel "0.7.0" :scope "test"] ; needed by bREPL @@ -22,6 +22,9 @@ '[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]] '[adzerk.bootlaces :refer [bootlaces! build-jar push-release]]) +(def +version+ "0.2.1") +(bootlaces! +version+) + (task-options! pom {:project (get-env :project) :version (get-env :version) @@ -40,16 +43,5 @@ (watch) (reload) (cljs-repl) - (cljs) )) - -(deftask build - "Build and install the JAR file" - [] - (comp - ;(merge-env! :resource-paths #{"src"}) - (pom) - (jar) - (install) )) - -(bootlaces! (get-env :version)) - + (cljs) + (target) )) diff --git a/doc/img/break-if.png b/doc/img/break-if.png new file mode 100644 index 0000000..b26ba50 Binary files /dev/null and b/doc/img/break-if.png differ diff --git a/doc/img/break.png b/doc/img/break.png new file mode 100644 index 0000000..c3f052f Binary files /dev/null and b/doc/img/break.png differ diff --git a/example/figwheel_server.log b/example/figwheel_server.log new file mode 100644 index 0000000..7c40ee9 --- /dev/null +++ b/example/figwheel_server.log @@ -0,0 +1,80 @@ +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 1.023 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.654 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.467 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.461 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.493 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.365 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.324 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.959 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.465 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.658 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.606 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +WARNING: Use of undeclared Var example.core/& at line 89 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.6 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.382 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +WARNING: Use of undeclared Var example.core/& at line 88 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +WARNING: Use of undeclared Var example.core/& at line 88 /home/philos/work/philos/debux/example/src/cljs/example/core.cljs +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.678 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.522 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.427 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.562 seconds.[0m +[0mCompiling "resources/public/js/app.js" from ["src/cljs"]... +notifying browser that file changed: resources/public/js/out/goog/deps.js +notifying browser that file changed: resources/public/js/out/cljs_deps.js +notifying browser that file changed: out/example/core.js +[32mSuccessfully compiled "resources/public/js/app.js" in 0.888 seconds.[0m diff --git a/example/project.clj b/example/project.clj index bb3799f..b0d412c 100644 --- a/example/project.clj +++ b/example/project.clj @@ -1,20 +1,17 @@ (defproject example "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.8.0"] - [org.clojure/clojurescript "1.7.228"] - [com.cemerick/piggieback "0.2.1"] - [weasel "0.7.0"] - [philoskim/debux "0.2.0"]] - :plugins [[lein-cljsbuild "1.0.5"] - [lein-figwheel "0.3.7"]] + [org.clojure/clojurescript "1.8.51"] + [philoskim/debux "0.2.1"]] + :plugins [[lein-cljsbuild "1.1.3"] + [lein-figwheel "0.5.1"]] :source-paths ["src/clj"] :clean-targets ^{:protect false} ["resources/public/js/app.js" "resources/public/js/app.js.map"] - :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} :cljsbuild {:builds [{:id "dev" :source-paths ["src/cljs"] :figwheel true - :compiler {:main "example.brepl" + :compiler {:main example.core :asset-path "js/out" :output-to "resources/public/js/app.js" :output-dir "resources/public/js/out" diff --git a/example/src/clj/example/core.clj b/example/src/clj/example/core.clj index 9f541d8..754d51a 100644 --- a/example/src/clj/example/core.clj +++ b/example/src/clj/example/core.clj @@ -21,11 +21,13 @@ ; Sometimes you need to see several forms evaluated. To do so, a literal vector ; form can be used like this. -(let [a (take 5 (range)) - {:keys [b c d] :or {d 10 b 20 c 30}} {:c 50 :d 100} - [e f g & h] ["a" "b" "c" "d" "e"]] +(defn my-fun + [a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]] (dbg [a b c d e f g h])) -; => [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] + +(my-fun (take 5 (range)) {:c 50 :d 100} ["a" "b" "c" "d" "e"]) +; => [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] + ; Notice that the printed value is a map, not a vector and the form ; is prepended with colon to differenciate the form from the evaluated value. @@ -44,7 +46,6 @@ ; java.lang.IllegalArgumentException ; Don't know how to create ISeq from: java.lang.Long - (dbg (-> "a b c d" .toUpperCase (.replace "A" "X") @@ -80,12 +81,13 @@ ; => ("2" "3") +(dbg (let [a (take 5 (range)) + {:keys [b c d] :or {d 10 b 20 c 30}} {:c 50 :d 100} + [e f g & h] ["a" "b" "c" "d" "e"]] + [a b c d e f g h])) +; => [(0 1 2 3 4) 20 50 100 "a" "b" "c" ("d" "e")] -(dbg (let [c (+ 1 2) - [d e] [5 6]] - (-> (+ d e) (- c)))) - (def c (dbg (comp inc inc +))) (c 10 20) diff --git a/example/src/cljs/example/brepl.cljs b/example/src/cljs/example/brepl.cljs deleted file mode 100644 index a727491..0000000 --- a/example/src/cljs/example/brepl.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns example.brepl - (:require [cljs.debux :refer-macros [dbg clog break]] - [weasel.repl :as ws-repl] )) - -(ws-repl/connect "ws://localhost:9001") - diff --git a/example/src/cljs/example/core.cljs b/example/src/cljs/example/core.cljs index 599a7b4..85a1a52 100644 --- a/example/src/cljs/example/core.cljs +++ b/example/src/cljs/example/core.cljs @@ -1,5 +1,5 @@ (ns example.core - (:require [cljs.debux :as d :refer-macros [clog break]])) + (:require [debux.cs.core :as d :refer-macros [clog dbg break]])) (clog (repeat 5 (clog (repeat 5 "x") "inner repeat")) @@ -15,13 +15,21 @@ (clog (+ 10 20) :style :debug "debug style") (clog (+ 10 20) "debug style is default") +;; Or in brief + +;; (clog (+ 10 20) :s :e "error style") +;; (clog (+ 10 20) :s :w "warn style") +;; (clog (+ 10 20) :s :i "info style") +;; (clog (+ 10 20) :s :d "debug style") +;; (clog (+ 10 20) "debug style is default") + + (d/merge-style {:warn "background: #9400D3; color: white" :love "background: #FF1493; color: white"}) (clog (+ 10 20) :style :warn "warn style changed") (clog (+ 10 20) :style :love "love style") - (clog (+ 10 20) :style "color:orange; background:blue; font-size: 14pt") @@ -56,3 +64,38 @@ (clog {:a 10 :b 20} :js) + +;;--------------- +;; break +;;--------------- + +(defn my-fun2 + [a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]] + (break) + (clog [a b c d e f g h])) + +;; (my-fun2 (take 5 (range)) {:c 50 :d 100} ["a" "b" "c" "d" "e"]) + +(defn my-fun3 [] + (let [a 10 + b 20] + (dotimes [i 1000] + (break :if (= i 999))))) + +;; (my-fun3) +;(enable-console-print!) + + +(clog (-> 10 + (+ 20))) + +(clog (->> 10 + (+ 20))) + +(clog (let [a 10 + [b & c] [20 30 40]] + [a b c])) + +(def c (clog (comp inc inc +))) + +(c 10 20) diff --git a/example/target/classes/META-INF/maven/example/example/pom.properties b/example/target/classes/META-INF/maven/example/example/pom.properties index c7090b5..c10ebc7 100644 --- a/example/target/classes/META-INF/maven/example/example/pom.properties +++ b/example/target/classes/META-INF/maven/example/example/pom.properties @@ -1,5 +1,5 @@ #Leiningen -#Wed Feb 24 21:40:18 KST 2016 +#Sat May 14 20:10:24 KST 2016 version=0.1.0-SNAPSHOT groupId=example artifactId=example diff --git a/src/debux/core.clj b/src/debux/core.clj index 0cf69e4..b31f5f4 100755 --- a/src/debux/core.clj +++ b/src/debux/core.clj @@ -198,7 +198,7 @@ msg (:msg opts2) pairs (partition 2 bindings) - syms (map (fn [sym] `(pp-subform '~sym ~sym ~n)) + syms (map (fn [sym] `(let [~'& '&] (pp-subform '~sym ~sym ~n))) (take-nth 2 bindings)) pps (map (fn [s e] [s e]) (repeat '_) syms) bindings' (interleave pairs pps)] @@ -250,3 +250,5 @@ 'comp `(dbg-comp ~form ~@opts) `(dbg-others ~form ~@opts)) `(dbg-others ~form ~@opts) )) + + diff --git a/src/debux/cs/core.clj b/src/debux/cs/core.clj index cf6a867..169222d 100755 --- a/src/debux/cs/core.clj +++ b/src/debux/cs/core.clj @@ -3,7 +3,7 @@ ;; These vars are actually defined in debux.cs/core.cljs file. (declare blanks insert-blanks println-dbg pprint-dbg - println-cgroup println-cgroup-end pprint-clog + println-clog println-cgroup println-cgroup-end pprint-clog pp-comp pp-subform changed? get-style style* ^:dynamic *indent-size*) @@ -186,7 +186,7 @@ js (:js opts2) style (:style opts2) - subforms2 (map insert-first subforms (repeat 'name)) + subforms2 (map insert-last subforms (repeat 'name)) pairs (map (fn [fst snd n] `(pp-subform '~fst ~snd ~n ~clog ~js)) subforms subforms2 (repeat n))] @@ -232,7 +232,7 @@ style (:style opts2) pairs (partition 2 bindings) - syms (map (fn [sym] `(pp-subform '~sym ~sym ~n ~clog ~js)) + syms (map (fn [sym] `(let [& '&] (pp-subform '~sym ~sym ~n ~clog ~js))) (take-nth 2 bindings)) pps (map (fn [s e] [s e]) (repeat '_) syms) bindings2 (interleave pairs pps)] @@ -251,14 +251,14 @@ (println-clog "=>") (pprint-clog return# ~js) (println-cgroup-end)) - (binding [*print-length* (or ~n 100) - *indent-size* (+ 2 *indent-size*)] - (println-dbg (str "\ndbg: (let " '~bindings " ...)" - (and ~msg (str " <" ~msg ">")) - (and ~once (str " (:once mode)")))) - (let ~(vec (apply concat bindings2)) ~@body) - (println-dbg "=>") - (pprint-dbg return#) )))) + (binding [*print-length* (or ~n 100) + *indent-size* (+ 2 *indent-size*)] + (println-dbg (str "\ndbg: (let " '~bindings " ...)" + (and ~msg (str " <" ~msg ">")) + (and ~once (str " (:once mode)")))) + (let ~(vec (apply concat bindings2)) ~@body) + (println-dbg "=>") + (pprint-dbg return#) )))) return#) )) (defmacro ^:private dbg-comp diff --git a/src/debux/cs/core.cljs b/src/debux/cs/core.cljs index 6fc4b96..fd455cc 100755 --- a/src/debux/cs/core.cljs +++ b/src/debux/cs/core.cljs @@ -78,7 +78,8 @@ (defn pprint-clog [return js] - (let [pp (str/trim (with-out-str (cljs.pprint/pprint return)))] + (let [& '& + pp (str/trim (with-out-str (cljs.pprint/pprint return)))] (.log js/console pp) (when js (.log js/console "%O" return) ))) diff --git a/src/debux/lab.clj b/src/debux/lab.clj new file mode 100644 index 0000000..3e29e5d --- /dev/null +++ b/src/debux/lab.clj @@ -0,0 +1,51 @@ +(ns debux.lab + (:require (clojure [string :as str] + [walk :as walk] + [pprint :as pp] ))) + +;;; For internal debugging + +(defmacro ^:private dbg_ + "The internal macro to debug dbg macro. +