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. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## Unreleased - ???
- Add `tracev` macro.
- Fix compiler bug that emitted incorrect code in some cases for while loops that create closures. - 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. - Add `:fresh` option to `(import ...)` to overwrite the module cache.
- `(range x y 0)` will return an empty array instead of hanging forever. - `(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))) (tuple 'fn (tuple '& $args) (tuple/slice parts 0)))
(defmacro tracev (defmacro tracev
"Displays the variables or literals listed, providing both the name and "Print a value and a description of the form that produced that value to
and the value for variables. Designed for quick debugging of values. Returns stderr. Evaluates to x."
the traced forms: nil for none, the form itself for one, and a tuple of the [x]
forms for many." (def s (gensym))
[& forms] ~(let [,s ,x]
(with-syms [results var] (,eprinf "trace %j is " ',x)
~(do (,eprintf (,dyn :pretty-format "%q") ,s)
(def ,results @[]) ,s))
,;(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)))))
(defmacro -> (defmacro ->
"Threading macro. Inserts x as the second value in the first form "Threading macro. Inserts x as the second value in the first form