1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-13 00:50:26 +00:00

Add a dbg macro for easy var dumping

This commit is contained in:
LouisJackman 2020-05-16 15:15:57 +01:00
parent 48d31ad7bc
commit fabb722c8d
No known key found for this signature in database
GPG Key ID: C83A456999EEBC34

View File

@ -945,6 +945,22 @@
(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
"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."
[& forms]
~(do
,;(map (fn [arg]
(def preface (if (symbol? arg)
(string "`" arg "` has value ")
"Literal has value "))
~(do
(prin ,preface)
(pp ,arg)
nil))
forms)))
(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