diff --git a/CHANGELOG.md b/CHANGELOG.md index edbc8393..19a208e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index f55c073f..291c0c57 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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