Skip to content

Commit 722522b

Browse files
committed
Add expr macro as simplified version of spy>>
1 parent 831bf0b commit 722522b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/postmortem/core.cljc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@
231231
([session key xform x] (spy> x session key xform)))
232232

233233
(macros/deftime
234-
235234
(defmacro locals
236235
"Creates and returns a local environment map at the call site.
237236
A local environment map is a map of keyword representing each local name
@@ -255,6 +254,13 @@
255254
([session key xform]
256255
`(spy> (locals) ~session ~key ~xform)))
257256

257+
(defmacro expr
258+
"A simplified version of spy>>. Same as (spy>> '<expr> <expr>)."
259+
{:added "0.5.3"}
260+
([e] `(expr ~e identity))
261+
([e xform] `(expr (current-session) ~e ~xform))
262+
([session e xform] `(spy> ~e ~session '~e ~xform)))
263+
258264
)
259265

260266
(defn make-logger
@@ -277,7 +283,7 @@
277283

278284
(defn make-multi-logger
279285
"Creates a multi logger.
280-
286+
281287
A multi logger is a variant of the simple logger. If called with
282288
two arguments, it acts like `(spy>> <arg1> <arg2>)` on the implicit
283289
session. If called with one argument, it acts like (log-for <arg>)`.

test/postmortem/core_test.cljc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@
8787
(is (= {} (pm/logs)))
8888
(is (= {} (pm/stats))))
8989

90+
(deftest ^:eftest/synchronized expr-test
91+
(is (= 15
92+
(loop [i 5, sum 0]
93+
(if (zero? i)
94+
sum
95+
(recur (dec i) (pm/expr (+ i sum)))))))
96+
(is (= [5 9 12 14 15]
97+
(pm/log-for '(+ i sum))))
98+
(pm/reset!))
99+
90100
;; Assert this function definition compiles
91101
;; cf. https://github.com/athos/postmortem/issues/2
92102
(defn regression-2 [^long x]

0 commit comments

Comments
 (0)