8000 Add expr macro as simplified version of spy>> by athos · Pull Request #21 · athos/Postmortem · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add expr macro as simplified version of spy>> #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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
Loading
0