### Run Clojure Examples with Leiningen Source: https://github.com/philoskim/debux/blob/master/examples/README.adoc Instructions to clean and run Clojure examples using the Leiningen build tool. Assumes Leiningen is installed and configured. ```shell lein clean lein run ``` -------------------------------- ### Run Babashka Examples Source: https://github.com/philoskim/debux/blob/master/examples/README.adoc Command to execute examples using Babashka, a built-in task runner for Clojure. Assumes Babashka is installed. ```shell bb -m examples.core ``` -------------------------------- ### Run ClojureScript Examples with Yarn Source: https://github.com/philoskim/debux/blob/master/examples/README.adoc Steps to install dependencies, clean, and test ClojureScript examples using Yarn. Includes instructions for accessing results via browser DevTools. ```shell yarn install yarn clean yarn test ``` -------------------------------- ### Manual ClojureScript DevTools Installation Source: https://github.com/philoskim/debux/blob/master/README.adoc Provides a manual method for installing `cljs-devtools` in a ClojureScript project, enabling its use with Debux. ```clojure (ns your-project.devtools (:require [devtools.core :as devtools])) (devtools/install!) ``` -------------------------------- ### Baboskha Dependency Configuration for Debux Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows the `bb.edn` configuration file to set up dependencies for running Debux examples with Baboskha. ```clojure {:paths ["src/clj"] :deps {philoskim/debux {:mvn/version "0.9.1"} }} ``` -------------------------------- ### Add .cljc examples to Debux Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc This version of Debux includes examples for `.cljc` files in `example/src/cljc/example/common.cljc`. This demonstrates how to use Debux in shared Clojure and ClojureScript code. ```clojure ** `.cljc` examples are added to `example/src/cljc/example/common.cljc` file. ``` -------------------------------- ### Expand Type Macro Example Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates the `:expand-type` macro which expands and prints the output of a Clojure expression. It shows a pipeline of operations including `toUpperCase`, `replace`, `split`, and `first`. ```clojure (dbgn (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first)) ``` -------------------------------- ### Loop with Recur Example Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how `dbgn` supports debugging `loop` forms that include `recur`. This example calculates a factorial using a loop with an accumulator and a decrementing counter. ```clojure (dbgn (loop [acc 1 n 3] (if (zero? n) acc (recur (* acc n) (dec n))))) ``` -------------------------------- ### Register custom macros with `register-macros!` Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to register custom macros, such as `my-let`, using `register-macros!` to enable debugging with `dbgn`/`clogn`. Includes examples of showing registered macros and debugging a custom macro. ```clojure (defmacro my-let [bindings & body] `(let ~bindings ~@body)) ``` ```clojure (register-macros! :let-type [my-let]) ``` ```clojure (dbg (show-macros :let-type)) ``` ```clojure (dbg (show-macros)) ``` ```clojure (dbgn (my-let [a 10 b (+ a 10)] (+ a b))) ``` -------------------------------- ### Cond-> Macro Example Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging with `cond->`, which conditionally threads expressions through a series of transformations. This example builds a vector based on the parity of `x` and `y`. ```clojure (let [x 1 y 2] (dbgn (cond-> [] (odd? x) (conj "x is odd") (zero? (rem y 3)) (conj "y is divisible by 3") (even? y) (conj "y is even")))) ``` -------------------------------- ### Clojure: Debugging :case-type macro with string matching Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to debug a case macro that matches against a string value. This example demonstrates debux tracing the evaluation of the case statement and identifying the matching branch. ```clojure (dbgn (let [mystr "hello"] (case mystr "" 0 "hello" (count mystr)))) ; => 5 ``` -------------------------------- ### Dot Type Macro Example Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates the `:dot-type` macro for invoking Java methods on Clojure objects. This example calls the `getMonth` method on a `java.util.Date` object. ```clojure (dbgn (. (java.util.Date.) getMonth)) ``` -------------------------------- ### Evaluating Multiple Forms with `dbgn` in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows the usage of the `dbgn` macro, similar to `dbg` but providing named outputs for each form, making debugging more organized. This example evaluates a vector of arguments. ```clojure (defn my-fun2 [a {:keys [b c d] :or {d 10 b 20 c 30}} [e f g & h]] (dbgn [a b c d e f g h])) (my-fun2 (take 5 (range)) {:c 50 :d 100} ["a" "b" "c" "d" "e"]) ``` -------------------------------- ### Clojure: Debugging :for-type macro with let and when clauses Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging a for loop that includes :let and :when clauses. This example shows how debux tracks the iteration process, variable bindings, and conditional filtering within the for macro. ```clojure (dbgn (for [x [0 1 2 3 4 5] :let [y (* x 3)] :when (even? y)] y)) ; => (0 6 12) ``` -------------------------------- ### Conditional Logic Example Source: https://github.com/philoskim/debux/blob/master/README.adoc This example shows debugging of a function that uses `..` for method invocation and `contains` for checking substring presence. It converts a string to lowercase and checks if it contains a specific substring. ```clojure (dbgn (.. "fooBAR" toLowerCase (contains "ooba"))) ``` -------------------------------- ### Clojure: Skip form itself and print nothing with dbgn Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates a scenario where `dbgn` ignores the entire form and prints nothing. This example uses a `try-catch` block to handle an arithmetic exception. ```clojure (dbgn (try (/ 1 0) (catch ArithmeticException e (str "caught exception: " (.getMessage e))))) ``` -------------------------------- ### Clojure: Debugging :skip-arg-1-type macro with precision setting Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates the :skip-arg-1-type macro, where the first argument is not evaluated. This example uses `with-precision` to show how debux skips the evaluation of the precision argument and traces the subsequent calculation. ```clojure (dbgn (with-precision 10 (/ 1M 6))) ; => 0.1666666667M ``` -------------------------------- ### Clojure: Skip all arguments and print outermost form with dbgn Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how `dbgn` can be used with macros that ignore all arguments and print only the outermost form and its result. This example defines a simple `unless` macro. ```clojure (dbgn (defmacro unless [pred a b] `(if (not ~pred) ~a ~b))) ``` -------------------------------- ### Install Debux Library in project.clj Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This snippet shows how to add the Debux library as a dependency in a Clojure project's `project.clj` file. It specifies the group ID, artifact ID, and version. ```clojure [philoskim/debux "0.2.1"] ``` -------------------------------- ### Clojure: Debugging :skip-arg-2-type macro with as-> Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates the :skip-arg-2-type macro, where the second argument is not evaluated. This example uses the `as->` macro to show how debux skips the initial binding of the variable and traces subsequent transformations. ```clojure (dbgn (as-> 0 n (inc n) (inc n))) ; => 2 ``` -------------------------------- ### Debug Composition Form (comp) in Clojure Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This example shows how to use `dbg` to debug a composition form created with `comp`. It prints the result of each function in the composition sequence as it's applied. ```clojure (def c (dbg (comp inc inc +))) (c 10 20) ``` -------------------------------- ### Setting the line bullet for Debux output Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to customize the line bullet character used in Debux output. Examples demonstrate changing the bullet to a semicolon and then to a space. ```clojure (set-line-bullet! ";") (dbg (+ 20 30)) (dbgn (* 10 (+ 2 3))) (set-line-bullet! " ") (dbg (+ 20 30)) (dbgn (* 10 (+ 2 3))) ``` -------------------------------- ### Using Debux Macros on Node.js (Clojure) Source: https://github.com/philoskim/debux/blob/master/README.adoc Explains how to use Debux macros (`dbg`/`dbgn`) in a Node.js environment, highlighting that `dbg`/`dbgn` are preferred over `clog`/`clogn` due to Node.js's console limitations regarding colors. It shows an example with both `dbgn` and `clogn`. ```clojure (ns examples.node (:require [cljs.nodejs :as nodejs] [debux.cs.core :refer-macros [clog clogn dbg dbgn]] )) (defn -main [& args] (dbgn (+ 2 (* 3 4))) (clogn (+ 2 (* 3 4)))) (set! *main-cli-fn* -main) ``` -------------------------------- ### Debugging Composed Transducers with dbgt in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging composed transducers in Clojure using `dbgt`. The example traces data through a composition of `map` and `filter` transducers, visualizing the intermediate transformations and the final result. ```clojure ;Debugging composed transducers (transduce (dbgt (comp (map inc) (filter odd?))) conj (range 5)) .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] ----- ``` -------------------------------- ### Debug Thread-First Macro (->) in Clojure Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This example illustrates debugging a thread-first macro (`->`) using `dbg`. It shows how `dbg` prints the intermediate results of each step within the macro, helping to trace execution. ```clojure (dbg (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first)) ``` -------------------------------- ### Apply CSS Styles with clog/clogn in ClojureScript Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to use clog and clogn with CSS styling in Chrome DevTools. Includes examples of predefined styles like :error, :warn, :info, :debug, and how to define custom styles using merge-styles. ```clojurescript (ns example.core (:require [debux.cs.core :as d :refer-macros [clog clogn dbg dbgn break]])) (clog (repeat 5 "x") "5 times repeat") (clogn (repeat 5 (repeat 5 "x")) "25 times repeat") ``` ```clojurescript (clog (+ 10 20) :style :error "error style") (clog (+ 10 20) :style :warn "warn style") (clog (+ 10 20) :style :info "info style") (clog (+ 10 20) :style :debug "debug style") (clog (+ 10 20) "debug style is default") ``` ```clojurescript (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") ``` ```clojurescript (d/merge-styles {: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") ;; You can style the form directly in string format in any way you want. (clog (+ 10 20) :style "color:orange; background:blue; font-size: 14pt") ``` -------------------------------- ### Clojure: Skip evaluation of second and third arguments with dbgn Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates using `dbgn` to debug macros that require the second and third arguments to be skipped during evaluation. This example uses `areduce` for array reduction. ```clojure (let [xs (float-array [1 2 3])] (dbgn (areduce xs i ret (float 0) (+ ret (aget xs i))))) ; => 6.0 ``` -------------------------------- ### Debugging Thread-First Macro with Data Access in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc An example of using `dbg` to debug a thread-first macro that accesses nested data structures. It traces the path through a map to retrieve a specific value. ```clojure (def person {:name "Mark Volkmann" :address {:street "644 Glen Summit" :city "St. Charles" :state "Missouri" :zip 63304} :employer {:name "Object Computing, Inc." :address {:street "12140 Woodcrest Dr." :city "Creve Coeur" :state "Missouri" :zip 63141}}}) (dbg (-> person :employer :address :city)) ``` -------------------------------- ### Debug Clojure Thread Macro `->>` with `dbg` Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows an example of debugging a thread-last macro (`->>`) using the `dbg` macro. It demonstrates how `dbg` can be placed within the macro chain to inspect the results of a sequence of operations. ```clojure (->> [-1 0 1 2] (filter pos?) (map inc) dbg (map str)) ``` -------------------------------- ### Debug anonymous function in Clojure reduce Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates debugging an anonymous function used with `reduce` in Clojure. This example highlights how debux tracks the accumulator and current item during the reduction process. ```clojure (dbgn (reduce (fn [acc i] (+ acc i)) 0 [1 5 9])) ``` -------------------------------- ### Clojure: Debugging :case-type macro with symbol matching Source: https://github.com/philoskim/debux/blob/master/README.adoc Provides an example of debugging a case macro that matches against a symbol. This snippet illustrates debux's ability to trace symbol comparisons within a case statement and handle default cases. ```clojure (dbgn (case 'a (x y z) "x, y, or z" "default")) ; => "default" ``` -------------------------------- ### Debug Clojure `some->>` Macro with `dbg` Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates debugging Clojure's `some->>` (thread-last with potential nils) macro using `dbg`. This example shows how to inspect values as they pass through the macro, especially when operations might yield nil. ```clojure (dbg (some->> {:x 5 :y 10} :y (- 30))) ``` -------------------------------- ### Debug Clojure `cond->` Macro with `dbg` Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging Clojure's `cond->` macro using `dbg`. This example shows how `dbg` can trace the conditional application of functions within the macro, revealing which branches are taken and the intermediate results. ```clojure (def a 10) (dbg (cond-> a (even? a) inc (= a 20) (* 42) (= 5 5) (* 3))) ``` -------------------------------- ### Debug Clojure Thread Macro `->` with `dbg` (Exception Example) Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates an incorrect usage of the `dbg` macro within a thread-first macro (`->`) that leads to an `IllegalArgumentException`. This highlights the necessity of properly isolating the expression for debugging. ```clojure (-> {:a [1 2]} (dbg (get :a)) (conj 3)) ``` -------------------------------- ### Turning off source info line printing in Debux Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates how to disable the printing of source file and line number information for Debux macros using `set-source-info-mode!`. Includes examples of turning it off and then back on. ```clojure (set-source-info-mode! false) (dbg (+ 2 3)) (dbgn (* 10 (+ 2 3))) (set-source-info-mode! true) (dbg (+ 20 30)) (dbgn (* 10 (+ 2 3))) ``` -------------------------------- ### Debug Clojure `some->` Macro with `dbg` Source: https://github.com/philoskim/debux/blob/master/README.adoc Provides an example of debugging Clojure's `some->` threading macro using `dbg`. It shows how `dbg` can be used to trace the execution flow and intermediate values when dealing with potentially nil results. ```clojure (dbg (some-> {:a 10} :b inc)) ``` -------------------------------- ### Debug Clojure `cond->>` Macro with `dbg` Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows an example of debugging Clojure's `cond->>` (thread-last with conditionals) macro using `dbg`. It highlights how `dbg` can trace the conditional logic and the values passed between operations in a thread-last context. ```clojure (def b 10) (dbg (cond->> b (even? b) inc (= b 20) (- 42) (= 2 2) (- 30))) ``` -------------------------------- ### Correct Debux Usage in Thread Macro Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This example shows the correct way to use `dbg` within a thread macro chain. It highlights that `dbg` should be a separate step in the chain, not an argument to a function within the macro, to avoid errors. ```clojure (-> {:a [1 2]} (get :a) dbg (conj 3)) ``` -------------------------------- ### Safe Debugging in Multi-Threads with Debux Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates safe debugging across multiple threads in Clojure using Debux macros (`dbg`). The example shows how messages from different threads are printed distinctly without intermingling, ensuring clarity in concurrent debugging scenarios. ```clojure ;Safe debugging in multi-threads programming. (defn my-fn [thread-no] (dbg (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) :msg (str "thread-no: " thread-no))) (future (Thread/sleep 1000) (my-fn 1)) (future (Thread/sleep 1000) (my-fn 2)) (future (Thread/sleep 1000) (my-fn 3)) (dbg (* 2 5)) (shutdown-agents) .REPL output ----- {:ns examples.lab, :line 45} dbg: (* 2 5) => | 10 {:ns examples.lab, :line 26} dbg: (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) => | "a b c d" => | "a b c d" | .toUpperCase => | "A B C D" | (.replace "A" "X") => | "X B C D" | (.split " ") => | ["X" "B" "C" "D"] | first => | "X" {:ns examples.lab, :line 26} dbg: (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) => | "a b c d" => | "a b c d" | .toUpperCase => | "A B C D" | (.replace "A" "X") => | "X B C D" | (.split " ") => | ["X" "B" "C" "D"] | first => | "X" {:ns examples.lab, :line 26} dbg: (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) => | "a b c d" => | "a b c d" | .toUpperCase => | "A B C D" | (.replace "A" "X") => | "X B C D" | (.split " ") => | ["X" "B" "C" "D"] | first => | "X" ----- ``` -------------------------------- ### Project Configuration for ClojureScript DevTools Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates how to set up the project.clj file to include `cljs-devtools` via `:preloads` for use with Debux. ```clojure (defproject your-project "0.1.0" :dependencies [[binaryage/devtools "1.0.2"] ,,,,,,] ,,,,,, :cljsbuild {:builds [{:compiler {:preloads [devtools.preload] ,,,,,,}}]}) ``` -------------------------------- ### Emacs CIDER Integration for debux Source: https://github.com/philoskim/debux/blob/master/README.adoc This section describes how to integrate the `debux.el` file into Emacs's `init.el` for CIDER users. It outlines the commands to insert or delete `dbg`/`dbgn` for `.clj`/`.cljc` files and `clog`/`clogn` for `.cljs` files. ```emacs-lisp (load-file "/path/to/debux.el") ;; Ensure debux.el is loaded in your init.el ``` -------------------------------- ### Clojure: Debugging a function with debux (dbgn) Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates the usage of the `dbgn` macro to trace function execution in Clojure. It shows how `dbgn` can capture arguments and return values, including handling optional arguments. ```clojure (defn foo [a b & [c]] (if c (* a b c) (* a b 100)))) (foo 2 3) ; => 600 (foo 2 3 10) ; => 60 ``` -------------------------------- ### Add `:print` option to dbg/clog in Debux Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc The `:print` option has been added to the `dbg` and `clog` macros in Debux. This allows for fine-grained control over what gets printed during debugging sessions. ```clojure ** `:print` option added to `dbg/clog`. ``` -------------------------------- ### Configure Project for ClojureScript Debugging with Figwheel Source: https://github.com/philoskim/debux/blob/master/README.adoc This snippet shows the `project.clj` configuration required to set up a ClojureScript project for development using Figwheel, including adding the debux dependency. ```clojure (defproject examples "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/clojurescript "1.10.238"] [philoskim/debux "0.9.1"]] :plugins [[lein-cljsbuild "1.1.6"] [lein-figwheel "0.5.10"]] :source-paths ["src/clj"] :clean-targets ^{:protect false} ["resources/public/js/app.js" "resources/public/js/app.js.map"] :cljsbuild {:builds [{:id "dev" :source-paths ["src/cljs"] :figwheel true :compiler {:main examples.core :asset-path "js/out" :output-to "resources/public/js/app.js" :output-dir "resources/public/js/out" :source-map true :optimizations :none} }]}) ``` -------------------------------- ### ClojureScript Project Configuration for Figwheel Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This snippet shows the `project.clj` file configuration for a ClojureScript project using Figwheel. It includes dependencies for Clojure, ClojureScript, and debux, along with Figwheel plugins and build settings for development. ```clojure (defproject example "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.8.0"] [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"] :cljsbuild {:builds [{:id "dev" :source-paths ["src/cljs"] :figwheel true :compiler {:main example.core :asset-path "js/out" :output-to "resources/public/js/app.js" :output-dir "resources/public/js/out" :source-map true :optimizations :none} }]}) ``` -------------------------------- ### Add Debux Stubs to Project Dependencies (Clojure) Source: https://github.com/philoskim/debux/blob/master/README.adoc Include the `philoskim/debux-stubs` library in your `project.clj` file for production dependencies. This provides the same API as `debux` but with no runtime overhead. ```clojure [philoskim/debux-stubs "0.9.1"] ``` -------------------------------- ### Debug Clojure defn with doc-string Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates debugging a Clojure function defined with `defn`, including a doc-string. Shows the binding vector and the function's execution. ```clojure (dbgn (defn add "add doc string" [a b] (+ a b))) (add 10 20) ``` -------------------------------- ### Clog with predefined styles and abbreviations Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc Demonstrates using the clog function with predefined style keywords (:error, :warn, :info, :debug) and their corresponding abbreviations (:s, :e, :w, :i, :d) for styled logging output. ```clojure (clog (+ 10 20) :style :error "error style") (clog (+ 10 20) :style :warn "warn style") (clog (+ 10 20) :style :info "info style") (clog (+ 10 20) :style :debug "debug style") (clog (+ 10 20) "debug style is default") ``` ```clojure (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") ``` -------------------------------- ### Upgrade minimum Clojure version and remove ClojureScript dependency Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc Debux version 0.9.0 upgrades the minimum required Clojure version to 1.10.0. It also removes the ClojureScript dependency from Clojure, simplifying project setup. ```clojure ** The minimum version of Clojure is upgraded from 1.8.0 to 1.10.0 ** ClojureScript dependency in Clojure removed. ``` -------------------------------- ### Debux macros for Electric (Clojure & ClojureScript) Source: https://github.com/philoskim/debux/blob/master/README.adoc Defines server-side and client-side macros for the Electric framework. Includes namespaces and macro lists for both server (Clojure) and client (ClojureScript) environments. ```clojure ;;; The server side macros for Electric debux.electric namespace: dbg, dbgn, dbgt, dbg-last, dbg_, dbgn_, dbgt_, dbg-last_ ;;; The client side macros for Electric debux.cs.electric namespace: clog, clogn, clogt, clog-last, clog_, clogn_, clogt_, clog-last_ dbg, dbgn, dbgt, dbg-last, dbg_, dbgn_, dbgt_, dbg-last_ ``` ```clojure (ns user.demo-toggle (:require [hyperfiddle.electric :as e] [hyperfiddle.electric-dom2 :as dom] [hyperfiddle.electric-ui4 :as ui] #?(:cljs [debux.cs.electric :refer-macros [clog clogn clogt clog-last clog_ clogn_ clogt_ clog-last_ dbg dbgn dbgt dbg-last dbg_ dbgn_ dbgt_ dbg-last_]]) ) #?(:clj (use 'debux.electric)) #?(:clj (defonce !x (atom true))) ; server state (e/def x (e/server (e/watch !x))) ; reactive signal derived from atom (e/defn Toggle [] (e/client (dom/h1 (dom/text "Toggle Client/Server")) (dom/div (dom/text "number type here is: " (case x true (e/client (clogn (pr-str (type 1)))) ;; <-- Here false (e/server (dbgn (pr-str (type 1))) )))) (dom/div (dom/text "current site: " (case x true "ClojureScript (client)" false "Clojure (server)"))) (ui/button (e/fn [] (e/server (swap! !x not))) (dom/text "toggle client/server")))) ``` -------------------------------- ### Debug multi-arity Clojure defn Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging a Clojure function with multiple arities using `defn`. Shows how debux handles different function signatures and their evaluations. ```clojure (dbgn (defn my-add "my-add doc string" ([] 0) ([a] a) ([a b] (+ a b)) ([a b & more] (apply + a b more)))) (my-add 10 20 30 40) ``` -------------------------------- ### Configuring ClojureScript DevTools for Debux Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to enable cljs-devtools integration within Debux by calling `set-cljs-devtools!` and configuring the ClojureScript build. ```clojure (debux.cs.core/set-cljs-devtools! true) ``` -------------------------------- ### Add Debux to Project Dependencies (Clojure) Source: https://github.com/philoskim/debux/blob/master/README.adoc Include the `philoskim/debux` library in your `project.clj` file for development dependencies to enable debugging features. ```clojure [philoskim/debux "0.9.1"] ``` -------------------------------- ### Add tap> support and set-tap-output! function in Debux Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc This update introduces support for `tap>` in Debux, allowing for better integration with Clojure's tap system. It also adds the `set-tap-output!` function for configuring tap output. ```clojure ** `tap>` support added. *** `set-tap-output!` function added. *** `set-date-time-fn!` function added. ``` -------------------------------- ### ClojureScript REPL Debugging with debux Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates how to require debux macros in a ClojureScript REPL and use `dbg` for debugging. The output of `dbg` is shown in both the REPL and the browser's console. ```clojurescript (require '[debux.cs.core :refer-macros [clog clogn dbg dbgn break]]) (dbg (+ 1 2)) ``` -------------------------------- ### Multiple dbgn and dbg Usage in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates how to use multiple `dbgn` and `dbg` macros within Clojure functions to trace execution and values. It shows nested calls and the resulting REPL output, highlighting the captured intermediate values and final results. ```clojure ;.Example 1 (def n 10) (defn add [a b] (dbgn (+ a b))) (defn mul [a b] (dbgn (* a b))) (dbgn (+ n (mul 3 4) (add 10 20))) ; => 52 ;.REPL output ----- {:ns examples.demo, :line 290} dbgn: (+ n (mul 3 4) (add 10 20)) => | n => | 10 |{:ns examples.demo, :line 288} |dbgn: (* a b) => || a => || 3 || b => || 4 || (* a b) => || 12 | (mul 3 4) => | 12 |{:ns examples.demo, :line 285} |dbgn: (+ a b) => || a => || 10 || b => || 20 || (+ a b) => || 30 | (add 10 20) => | 30 | (+ n (mul 3 4) (add 10 20)) => | 52 ----- ;.Example 2 .... (def n 10) (defn add2 [a b] (dbg (+ a b))) (defn mul2 [a b] (dbg (* a b))) (dbgn (+ n (mul2 3 4) (add2 10 20))) ; => 52 .... .REPL output ----- {:ns examples.demo, :line 299} dbgn: (+ n (mul2 3 4) (add2 10 20)) => | n => | 10 |{:ns examples.demo, :line 297} |dbg: (* a b) => || 12 | (mul2 3 4) => | 12 |{:ns examples.demo, :line 294} |dbg: (+ a b) => || 30 | (add2 10 20) => | 30 | (+ n (mul2 3 4) (add2 10 20)) => | 52 ----- ``` -------------------------------- ### Debux Tap Output Configuration and Usage (Clojure) Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates how to add a custom logging function to Debux's tap output, set a custom date-time format, and use dbg, dbgn, and dbgt with tap. ```clojure (ns examples.tap-output (:require [debux.tap-output :as d] [java-time.api :as jt]) (:gen-class)) (defn log [x] (spit "event.log" (str x \n) :append true)) (defn my-date-time [] (->> (jt/local-date-time) (jt/format :iso-date-time) )) (defn -main [] (println "\nRunning debux examples...\n") ;; add log function to tap (add-tap log) ;; For example, if you want to log the results of dbg/dbgn/dbgt ;; Firstly, run set-tap-output! function like this. (d/set-tap-output! true) ;; Optionally run set-date-time-fn! like this. ;; This will add :time info to the src-info line additionally. (d/set-date-time-fn! my-date-time) (d/dbg (+ 10 20)) (d/dbgn (+ 10 (* 2 3))) (transduce (dbgt (comp (map inc) (filter odd?))) conj (range 5))) ``` -------------------------------- ### Debug `defn` with `recur` (limitation) Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates debugging a `defn` macro using `dbgn` with `recur`. Shows the exception that occurs when `recur` is used without `loop` due to implementation restrictions. ```clojure (dbgn (defn factorial [acc n] (if (zero? n) acc (recur (* acc n) (dec n))))) ``` -------------------------------- ### Basic `dbg` Usage in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates the fundamental use of the `dbg` macro to print and pretty-print evaluated values without interrupting code execution. It shows how `dbg` works with simple arithmetic operations. ```clojure (dbg (+ 10 20)) ``` -------------------------------- ### Debug Clojure if-let binding Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates debugging an `if-let` expression in Clojure. Shows how debux tracks the value bound by the `if-let` and the subsequent conditional execution. ```clojure (def a* 10) (dbgn (if-let [s a*] (+ s 100) false)) ``` -------------------------------- ### Clojure: Skip evaluation of first and third arguments with dbgn Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates using `dbgn` to debug macros where the first and third arguments should not be evaluated. This is useful for metaprogramming in Clojure. ```clojure (defmulti greeting (fn [x] (:language x))) (dbgn (defmethod greeting :english [map] (str "English greeting: " (:greeting map)))) (dbgn (defmethod greeting :french [map] (str "French greeting: " (:greeting map)))) (def english-map {:language :english :greeting "Hello!"}) (def french-map {:language :french :greeting "Bonjour!"}) (greeting english-map) ; => "English greeting: Hello!" (greeting french-map) ; => "French greeting: Bonjour!" ``` -------------------------------- ### Register Custom Macro with Debux in ClojureScript Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates how to register a custom macro (my-let) with debux for tracing. It shows the `register-macros!` function and how to view registered macros using `show-macros`. ```clojurescript (ns example.macro) (defmacro my-let [bindings & body] `(let ~bindings ~@body)) ``` ```clojurescript (ns examples.demo (:require [debux.cs.core :as d :refer-macros [clog clogn dbg dbgn break]]) (:require-macros [examples.macro :refer [my-let]])) ;; Registering your own macro (d/register-macros! :let-type [my-let]) (dbg (d/show-macros :let-type)) (dbg (d/show-macros)) (clogn (my-let [a 10 b (+ a 10)] (+ a b))) ``` -------------------------------- ### Add Electric support to Debux Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc Debux version 0.8.3 includes support for Electric, a framework for building real-time web applications with Clojure. ```clojure ** Electric support added ``` -------------------------------- ### Clojure: Debugging a function definition with debux (dbgn) Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates how `dbgn` can be used to debug the definition of a function, including optional docstrings. It captures the evaluation of the function's body and the function's definition itself. ```clojure (dbgn (def my-function "my-function doc string" (fn [x] (* x x x)))) (my-function 10) ; => 1000 ``` -------------------------------- ### Debugging Single Transducer with dbgt in Clojure Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to use the `dbgt` macro in Clojure to debug a single transducer. It demonstrates tracing the data flow through a `filter` transducer, displaying the input and output at each step. ```clojure ;Debugging a single transducer (transduce (dbgt (filter odd?)) conj (range 5)) .REPL output ----- {:ns examples.lab, :line 5} dbgt: (filter odd?) |> 0 |< [] |> 1 |< [1] |> 2 |< [1] |> 3 |< [1 3] |> 4 |< [1 3] ----- ``` -------------------------------- ### Clog with user-defined styles Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc Shows how to define custom styles using `d/merge-style` and apply them to clog messages. It also demonstrates styling directly via a CSS string. ```clojure (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") ;; You can style the form directly in string format in any way you want. (clog (+ 10 20) :style "color:orange; background:blue; font-size: 14pt") ``` -------------------------------- ### Clojure: Debugging with :letfn-type macro Source: https://github.com/philoskim/debux/blob/master/README.adoc Demonstrates the usage of the :letfn-type macro for debugging nested function definitions. It shows how debux traces the execution of mutually recursive functions defined using letfn. ```clojure (dbgn (letfn [(twice [x] (* x 2)) (six-times [y] (* (twice y) 3))] (six-times 15))) ; => 90 ``` -------------------------------- ### Use Debux in Clojure Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This code demonstrates how to include the Debux library in a Clojure file using the `use` function from `debux.core`. This makes the library's debugging functions available for use. ```clojure (use 'debux.core) ``` -------------------------------- ### Debug Clojure let binding Source: https://github.com/philoskim/debux/blob/master/README.adoc Illustrates debugging a `let` binding in Clojure, including nested destructuring. Shows how debux tracks the values assigned to local variables within the `let` scope. ```clojure (dbgn (let [a (+ 1 2) [b c] [(+ a 10) (* a 2)]] (- (+ a b) c))) ``` -------------------------------- ### Fix `_prepost-map_` Handling in `defn`/`defn-` Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc Ensures that the `_prepost-map_` is correctly handled within `defn` and `defn-` definitions, resolving potential issues with macro expansion or code generation. ```clojure (defn my-func [_prepost-map_] ...) ``` -------------------------------- ### Add Production Mode Support with debux-stubs Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc Introduces the `debux-stubs` library to provide support for production mode, allowing debugging features to be optionally enabled or disabled without affecting production builds. ```clojure (require '[debux-stubs :as stubs]) (stubs/set-debug-mode! false) ``` -------------------------------- ### Debug chained Clojure function calls Source: https://github.com/philoskim/debux/blob/master/README.adoc Shows how to use multiple `dbgn` calls to debug a series of interconnected Clojure functions. This helps in tracing the flow of data through multiple function calls. ```clojure (dbgn (defn calc1 [a1 a2] (+ a1 a2))) (dbgn (defn calc2 [s1 s2] (- 100 (calc1 s1 s2)))) (dbgn (defn calc3 [m1 m2] (* 10 (calc2 m1 m2)))) (calc3 2 5) ``` -------------------------------- ### Add :simple option to Debux Source: https://github.com/philoskim/debux/blob/master/doc/change-logs.adoc Version 0.9.0 of Debux adds the `:simple` option, providing a simplified output format for debugging information. ```clojure ** `:simple` option added. ``` -------------------------------- ### Debug Let Binding in Clojure Source: https://github.com/philoskim/debux/blob/master/doc/v0.2.1/README.adoc This code snippet demonstrates debugging a `let` form using `dbg`. It shows how `dbg` prints the value of each binding within the `let` form, aiding in understanding variable assignments. ```clojure (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])) ```