-
-
Save luxbock/38d245ff1f1a194921cb to your computer and use it in GitHub Desktop.
boofoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro pr-> [& body] | |
(let [[init & exprs] body | |
syms (repeatedly (count body) gensym) | |
vals (mapcat (fn [exp sym prev] | |
[sym `(when-not (instance? Exception ~prev) | |
(try ~(if (seq? exp) | |
`(~(first exp) ~@(next exp) ~prev) | |
`(~exp ~prev)) | |
(catch Exception e# e#)))]) | |
exprs (rest syms) syms) | |
ress `(take-while identity ~(vec (rest syms)))] | |
`(let ~(vec (concat [(first syms) init] vals)) | |
(apply print-table | |
(format "-> %s" ~init) | |
(map vector | |
~(list `quote exprs) | |
~ress)) | |
(if (instance? Exception (last ~ress)) | |
(throw (last ~ress)) | |
(last ~ress))))) | |
boofoo.core> (pr-> 2 dec dec (/ 1) inc (+ 5)) | |
┌───────┬───────────────────────────────────────────────┐ | |
│ -> 2 │ value │ | |
├───────┼───────────────────────────────────────────────┤ | |
│ dec ╎ 1 │ | |
│ dec ╎ 0 │ | |
│ (/ 1) ╎ java.lang.ArithmeticException: Divide by zero │ | |
└───────┴───────────────────────────────────────────────┘ | |
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158) | |
boofoo.core> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment