1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 22:53:16 +00:00

Incorporate suggestions from PR

This commit is contained in:
LouisJackman 2020-05-16 20:18:00 +01:00
parent ca3dac7e87
commit 9109e369ff
No known key found for this signature in database
GPG Key ID: C83A456999EEBC34

View File

@ -945,24 +945,27 @@
(array/push parts (tuple apply f $args))) (array/push parts (tuple apply f $args)))
(tuple 'fn (tuple '& $args) (tuple/slice parts 0))) (tuple 'fn (tuple '& $args) (tuple/slice parts 0)))
(defmacro dbg (defmacro trace-pp
"Displays the variables or literals listed, providing both the name and "Displays the variables or literals listed, providing both the name and
and the value for variables. Designed for quick debugging of values and and the value for variables. Designed for quick debugging of values. Returns
nothing else." the traced forms: nil for none, the form itself for one, and a tuple of the
forms for many."
[& forms] [& forms]
(with-syms [results var] (with-syms [results var]
~(do ~(do
(def ,results @[]) (def ,results @[])
,;(map (fn [form] ,;(map (fn [form]
(def preface (if (symbol? form) (def preface (if (symbol? form)
(string "`" form "` has value ") (string form " is")
"Literal has value ")) "is"))
~(do ~(do
(prin ,preface) (def ,var ,form)
(def ,var ,form) (eprintf (string "%s " (dyn :pretty-format "%q"))
(pp ,var) ,preface
(array/push ,results ,var))) ,var)
forms) (eflush)
(array/push ,results ,var)))
forms)
(case (length ,results) (case (length ,results)
0 nil 0 nil
1 (,results 0) 1 (,results 0)