1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 08:50:27 +00:00

Merge pull request #401 from LouisJackman/add-dbg-core-macro

Add a dbg macro for easy var dumping
This commit is contained in:
Calvin Rose 2020-05-18 18:30:14 -04:00 committed by GitHub
commit ae5dc8c45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -946,6 +946,32 @@
(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 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)))))
(defmacro -> (defmacro ->
"Threading macro. Inserts x as the second value in the first form "Threading macro. Inserts x as the second value in the first form
in forms, and inserts the modified first form into the second form in forms, and inserts the modified first form into the second form