From df32cd0aca82dae908eb82b4c8ebb5bb15be0ad8 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 18 May 2020 17:43:41 -0500 Subject: [PATCH] Update tracev macro to be simpler and single arity. Reference #401 --- CHANGELOG.md | 1 + src/boot/boot.janet | 32 ++++++++------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) 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