Let's say we need evaluate a number of clauses in a source file, e.g.
test.clj
@(def x 1)
@(def y 2)
@(def z 3)
Only the last evaluation shows up if we plainly use either clj or lein repl,
user => (load-file "test.clj")
3
We can surround each of them by println to show all of them,
test-with-println.clj
(println @(def x 1))
(println @(def y 2))
(println @(def z 3))
user => (load-file "test-with-println.clj")
1
2
3
nil
What are the better alternatives to avoid invasive printlns all over the source code while able to print out all the intended evaluations under the umbrella of REPLs?
@Solution
Thanks to tap> from the answer @Sean Corfield we can have desired results as follows,
- pipe every wannabe printed out to
tap>.
test-with-tap.clj
(-> @(def x 1) tap>)
(-> @(def y 2) tap>)
(-> @(def z 3) tap>)
- REPLs will receive none of their outputs until
tap>is turned on byadd-tap.
user=> (load-file "test-with-tap.clj")
nil
user=> (add-tap @(def out (bound-fn* println)))
nil
user=> (load-file "test-with-tap.clj")
1
2
3
user=> (remove-tap out)
nil
user=> (load-file "test-with-tap.clj")
nil