From 9109e369ffbe09067443f9380bd7ffebdb65d719 Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sat, 16 May 2020 20:18:00 +0100 Subject: [PATCH] Incorporate suggestions from PR --- src/boot/boot.janet | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 1be6f4be..74303769 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -945,24 +945,27 @@ (array/push parts (tuple apply f $args))) (tuple 'fn (tuple '& $args) (tuple/slice parts 0))) -(defmacro dbg +(defmacro trace-pp "Displays the variables or literals listed, providing both the name and - and the value for variables. Designed for quick debugging of values and - nothing else." + 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] - (def preface (if (symbol? form) - (string "`" form "` has value ") - "Literal has value ")) - ~(do - (prin ,preface) - (def ,var ,form) - (pp ,var) - (array/push ,results ,var))) - forms) + (def preface (if (symbol? form) + (string form " is") + "is")) + ~(do + (def ,var ,form) + (eprintf (string "%s " (dyn :pretty-format "%q")) + ,preface + ,var) + (eflush) + (array/push ,results ,var))) + forms) (case (length ,results) 0 nil 1 (,results 0)