Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/pom.xml.asc
/.nrepl-port
/.idea
/print-foo.iml
/target
/lib
/classes
Expand Down
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

121 changes: 47 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,129 +1,104 @@
## print-foo
## print-foo-cljs

This is fork of [print-foo](https://github.com/AlexBaranosky/print-foo). I added Clojurescript support and did some other edits.

A Clojure library of print debugging macros.

Just add "print-" to the front of a normal `->>`, `->`, `let`, `defn`, `defn-`, `cond`, `if` and prints useful information.

If you're using [Cursive](https://cursive-ide.com/), I suggest creating macro or live template for prefixing `print-` or `pf/print-`

## Leiningen

```clj
[print-foo "1.0.1"]
[print-foo-cljs "2.0.3"]
```

## Usage

For Clojure
```clojure
(ns my-namespace
(:require [print.foo :as pf]))
```

For Clojurescript
```clojure
(ns my-namespace
(:require [print.foo :as pf :include-macros true]))
```


```clojure
print.foo=> (use 'print.foo)
nil

print.foo=> (+ 1 2 (print-and-return "ONE:: " (inc 4)))
ONE:: 4
7
ONE::5
=> 8

print.foo> (- 1000 (tap "RESULT:: " (+ 1 2 (inc 4))))
*** RESULT:: 8
8
*** RESULT::8
=> 992

print.foo> (def a (inc 4))
print.foo> (- 1000 (+ 1 2 (look a)))
*** A:: 8
8
*** A:: 5
=> 992

print.foo> (- 1000 (look (+ 1 2 (inc 4))))
*** (+ 1 2 (INC 4)):: 8
8
=> 992

print.foo=> (print-sexp (str (+ 3 4) (+ 5 (* 6 2)) 4))
3 3
4 4
(+ 3 4) 7
5 5
6 6
2 2
(* 6 2) 12
(+ 5 (* 6 2)) 17
4 4
(str (+ 3 4) (+ 5 (* 6 2)) 4) "7174"
=> "7174"


;; `print-sexp` is a code-walking macro that replaces
;; normal code like ->, ->>, let, cond, if,
;; etc, where possible with print.foo versions, and
;; wraps every sexp in print-and-return

print.foo=> (pprint
(macroexpand
'(print-sexp
(let [a (-> 5
inc
inc)
bs (->> [1 2 3 4 5 6]
(map inc)
(filter odd?))]
(println (apply + a bs))))))

;; =>
(let*
[a
(print.foo/print-and-return 'a " " (print.foo/print-> 5 inc inc))
bs
(print.foo/print-and-return
'bs
" "
(print.foo/print->> [1 2 3 4 5 6] (map inc) (filter odd?)))]
(print.foo/print-and-return
"let result: "
(do
(print.foo/print-and-return
'(println (apply + a bs))
" "
(println
(print.foo/print-and-return
'(apply + a bs)
" "
(apply + a bs)))))))

print.foo=> (print->> [1 2 3] (mapv inc) (mapv dec))
print.foo=> (print-->> [1 2 3] (mapv inc) (mapv dec))
[1 2 3] [1 2 3]
(mapv inc) [2 3 4]
(mapv dec) [1 2 3]
[1 2 3]
=> [1 2 3]

print.foo=> (print-> 1 inc dec inc dec)
print.foo=> (print--> 1 inc dec inc dec)
1 1
inc 2
dec 1
inc 2
dec 1
1
=> 1

print.foo=> (print-let [a 2 b 3 c (+ a b) d (+ c 7)] c)
a 2
b 3
c 5
d 12
let result: 5
5
=> 5

print.foo=> (print-defn f [a b] (* a b))
#'user/f
print.foo=> (f 3 4)
a 3
b 4
defn 'f' result: 12
12
=> 12

print.foo=> (print-defn- g [a b] (+ a b))
#'user/f
print.foo=> (g 3 4)
a 3
b 4
defn 'g' result: 7
7
defn- 'g' result: 7
=> 7

print.foo=> (print-cond nil 2 3 4)
test: 3 value: 4
4
test: 3
value: 4
=> 4

print.foo=> (print-cond-> {}
(pos? 1)
Expand All @@ -136,7 +111,7 @@ print.foo=> (print-cond-> {}
(merge {:c 3}))
test: (pos? 1) value: {:a 1}
test: (pos? 2) value: {:a 1, :b 2}
{:b 2, :a 1}
=> {:a 1, :b 2}

(print-cond->> [1 2 3]
(pos? 1)
Expand All @@ -145,12 +120,12 @@ test: (pos? 2) value: {:a 1, :b 2}
(neg? 2)
(map dec))
test: (pos? 1) value: (2 3 4)
(2 3 4)
=> (2 3 4)

print.foo=> (print-if (odd? 9) 1 2)
(odd? 9) true
1 1
1
=> 1

print.foo> (middleware->
{:get-in [:session]
Expand All @@ -169,7 +144,7 @@ print.foo> (middleware->
(fn [y]
(x (assoc y :m3 true))))

((middleware-> {:timings? false
((middleware-> {:timings? true
:get-in [:session]}
m1
m2
Expand All @@ -183,20 +158,18 @@ print.foo> (middleware->
{:token 1}
"REQUEST - GOING INTO: m2"
{:token 1}
{:m2 true, :m3 true, :session {:token 1}}
{:session {:token 1}, :m3 true, :m2 true}
"RESPONSE - COMING OUT OF: m2"
{:token 1}
"RESPONSE - COMING OUT OF: m3"
{:token 1}
{:middleware-timings
[{:middleware "m2", :middleware-elapsed 1}
{:middleware "m3", :middleware-elapsed 3}]}
=> {:session {:token 1}, :m3 true, :m2 true}

```

## Author

* [Alex Baranosky](https://github.com/AlexBaranosky)

## License

Copyright © 2013 Alex Baranosky

Distributed under the MIT License
18 changes: 8 additions & 10 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(defproject print-foo "1.0.2"
:description "A set of useful print-debugging tools"
:url "https://github.com/AlexBaranosky/print-foo"
(defproject print-foo-cljs "2.0.3"
:description "A set of useful print-debugging tools for both Clojure & Clojurescript"
:url "https://github.com/madvas/print-foo-cljs"
:license {:name "MIT License"
:url "http://mit-license.org/"}
:dependencies [[org.clojure/clojure "1.5.1"]
[gui-diff "0.6.6"]]
:profiles {:dev {:dependencies [[org.clojars.runa/conjure "2.2.0"]]
:plugins [[jonase/eastwood "0.0.2"]]}}
:deploy-repositories [["clojars" {:url "https://clojars.org/repo/"
:sign-releases false}]])
:url "http://mit-license.org/"}
:dependencies [[org.clojure/clojure "1.8.0"]
[binaryage/devtools "0.8.1"]]
:profiles {:dev {:dependencies []
:plugins []}})
Loading