Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid debux specific forms coming back in the output? #29

Open
ryrobes opened this issue Oct 23, 2022 · 3 comments
Open

Avoid debux specific forms coming back in the output? #29

ryrobes opened this issue Oct 23, 2022 · 3 comments

Comments

@ryrobes
Copy link

ryrobes commented Oct 23, 2022

Hi, is there any way to avoid having the output include internal debux forms like wrapping (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (or extra do blocks) on to submitted sub-forms, etc - and just returning the orignals? Thanks!

@philoskim
Copy link
Owner

philoskim commented Oct 24, 2022

If my understanding about your question is right, the answer might be as follows.

https://github.com/philoskim/debux#81-dbg-inside-dbgn-or-vice-versa

dbg can be used selectively inside dbgn like this, if you want to avoid printing a deeply nested structure inside dbgn.

(let [a 10 b 9 c 8 d 7 e 6 f 5 g 4 h 3]
  (dbgn (* a b (dbg (+ c d (- e f (* g h)))))))
; => 360

The above dbg will prevent dbgn from printing (+ c d (- e f (* g h)))) recursively.

REPL output

{:ns example.demo, :line 15}
dbgn: (* a b (+ c d (- e f (* g h)))) =>
| a =>
|   10
| b =>
|   9

|{:ns example.demo, :line 15}
|dbg: (+ c d (- e f (* g h))) =>
||   4
| (* a b (dbg (+ c d (- e f (* g h))))) =>
|   360

If my answer is not what you expected, please show me a concrete example that you want in more detailed way!

@ryrobes
Copy link
Author

ryrobes commented Oct 25, 2022

Appreciate the response! No, I def want all the nested return forms... but let me give you an example.

If I am wrapping dbgn over a form...

(use 'debux.core)

(dbgn (into {}
            (clojure.core/map (fn [x]
                   (let [kk (keyword x)
                         vv (clojure.core/rand-int 123)]
                     {kk vv}))
              ["goose" "maverick" "iceman" "joker"])))

I'll get this in return:

{:ns user, :line 3}
dbgn: (into {} (clojure.core/map (fn [x] (let [kk (keyword x) vv (clojure.core/rand-int 123)] {kk vv})) ["goose" "maverick" "iceman" "joker"])) =>
| {} =>
|   {}
| (fn [x] (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (debux.common.util/insert-blank-line) (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}))) =>
|   #object[user$eval74563$result__779__auto____74566 0x34d2bfa9 "user$eval74563$result__779__auto____74566@34d2bfa9"]
| ["goose" "maverick" "iceman" "joker"] =>
|   ["goose" "maverick" "iceman" "joker"]
 
|| x =>
||   "goose"
|| (keyword x) =>
||   :goose
|| (clojure.core/rand-int 123) =>
||   37
 
|| {kk vv} =>
||   {:goose 37}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:goose 37}
 
|| x =>
||   "maverick"
|| (keyword x) =>
||   :maverick
|| (clojure.core/rand-int 123) =>
||   73
 
|| {kk vv} =>
||   {:maverick 73}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:maverick 73}
 
|| x =>
||   "iceman"
|| (keyword x) =>
||   :iceman
|| (clojure.core/rand-int 123) =>
||   121
 
|| {kk vv} =>
||   {:iceman 121}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:iceman 121}
 
|| x =>
||   "joker"
|| (keyword x) =>
||   :joker
|| (clojure.core/rand-int 123) =>
||   22
 
|| {kk vv} =>
||   {:joker 22}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:joker 22}
| (clojure.core/map (fn [x] (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (debux.common.util/insert-blank-line) (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}))) ["goose" "maverick" "iceman" "joker"]) =>
|   ({:goose 37} {:maverick 73} {:iceman 121} {:joker 22})
| (into {} (clojure.core/map (fn [x] (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (debux.common.util/insert-blank-line) (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}))) ["goose" "maverick" "iceman" "joker"])) =>
|   {:goose 37, :maverick 73, :iceman 121, :joker 22}

Is it possible to get the forms back in the same fashion but without the injected debux wrappings?

i.e. return

|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] {kk vv}) =>
||   {:goose 37}

instead of

|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:goose 37}

or (less trivial to remove) return this

|| {kk vv} =>
||   {:joker 22}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] {kk vv}) =>
||   {:joker 22}
| (clojure.core/map (fn [x] (let [kk (keyword x) vv (clojure.core/rand-int 123)] {kk vv}))) ["goose" "maverick" "iceman" "joker"]) =>
|   ({:goose 37} {:maverick 73} {:iceman 121} {:joker 22})
| (into {} (clojure.core/map (fn [x] (let [kk (keyword x) vv (clojure.core/rand-int 123)] {kk vv}))) ["goose" "maverick" "iceman" "joker"])) =>
|   {:goose 37, :maverick 73, :iceman 121, :joker 22}

instead of this

|| {kk vv} =>
||   {:joker 22}
|| (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}) =>
||   {:joker 22}
| (clojure.core/map (fn [x] (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (debux.common.util/insert-blank-line) (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}))) ["goose" "maverick" "iceman" "joker"]) =>
|   ({:goose 37} {:maverick 73} {:iceman 121} {:joker 22})
| (into {} (clojure.core/map (fn [x] (clojure.core/binding [debux.common.util/*indent-level* (clojure.core/inc debux.common.util/*indent-level*)] (clojure.core/reset! (:evals +debux-dbg-opts+) {}) (debux.common.util/insert-blank-line) (let [kk (keyword x) vv (clojure.core/rand-int 123)] (debux.common.util/insert-blank-line) {kk vv}))) ["goose" "maverick" "iceman" "joker"])) =>
|   {:goose 37, :maverick 73, :iceman 121, :joker 22}

Essentially returning the original source forms, sub-forms instead of mutated versions with embedded debux fns wrapped inside them? Hope that helps explain my question.

@philoskim
Copy link
Owner

I'll fix this problem as soon as possible. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants