Skip to content

Commit

Permalink
Add expr macro as simplified version of spy>>
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Dec 10, 2024
1 parent 831bf0b commit 722522b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/postmortem/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
([session key xform x] (spy> x session key xform)))

(macros/deftime

(defmacro locals
"Creates and returns a local environment map at the call site.
A local environment map is a map of keyword representing each local name
Expand All @@ -255,6 +254,13 @@
([session key xform]
`(spy> (locals) ~session ~key ~xform)))

(defmacro expr
"A simplified version of spy>>. Same as (spy>> '<expr> <expr>)."
{:added "0.5.3"}
([e] `(expr ~e identity))
([e xform] `(expr (current-session) ~e ~xform))
([session e xform] `(spy> ~e ~session '~e ~xform)))

)

(defn make-logger
Expand All @@ -277,7 +283,7 @@

(defn make-multi-logger
"Creates a multi logger.
A multi logger is a variant of the simple logger. If called with
two arguments, it acts like `(spy>> <arg1> <arg2>)` on the implicit
session. If called with one argument, it acts like (log-for <arg>)`.
Expand Down
10 changes: 10 additions & 0 deletions test/postmortem/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
(is (= {} (pm/logs)))
(is (= {} (pm/stats))))

(deftest ^:eftest/synchronized expr-test
(is (= 15
(loop [i 5, sum 0]
(if (zero? i)
sum
(recur (dec i) (pm/expr (+ i sum)))))))
(is (= [5 9 12 14 15]
(pm/log-for '(+ i sum))))
(pm/reset!))

;; Assert this function definition compiles
;; cf. https://github.com/athos/postmortem/issues/2
(defn regression-2 [^long x]
Expand Down

0 comments on commit 722522b

Please sign in to comment.