Update tracev macro to be simpler and single arity.

Reference #401
This commit is contained in:
Calvin Rose 2020-05-18 17:43:41 -05:00
parent ae5dc8c45b
commit df32cd0aca
2 changed files with 9 additions and 24 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased - ???
- Add `tracev` macro.
- Fix compiler bug that emitted incorrect code in some cases for while loops that create closures.
- Add `:fresh` option to `(import ...)` to overwrite the module cache.
- `(range x y 0)` will return an empty array instead of hanging forever.

View File

@ -947,30 +947,14 @@
(tuple 'fn (tuple '& $args) (tuple/slice parts 0)))
(defmacro tracev
"Displays the variables or literals listed, providing both the name and
and the value for variables. Designed for quick debugging of values. Returns
the traced forms: nil for none, the form itself for one, and a tuple of the
forms for many."
[& forms]
(with-syms [results var]
~(do
(def ,results @[])
,;(map (fn [form]
~(do
(def ,var ,form)
(eprintf (string "trace "
(dyn :pretty-format "%q")
" is "
(dyn :pretty-format "%q"))
',form
,var)
(eflush)
(array/push ,results ,var)))
forms)
(case (length ,results)
0 nil
1 (,results 0)
(tuple ;,results)))))
"Print a value and a description of the form that produced that value to
stderr. Evaluates to x."
[x]
(def s (gensym))
~(let [,s ,x]
(,eprinf "trace %j is " ',x)
(,eprintf (,dyn :pretty-format "%q") ,s)
,s))
(defmacro ->
"Threading macro. Inserts x as the second value in the first form