1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-16 10:19:55 +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)))
(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)