From fabb722c8df6b4b049c13d84f83d9f07c2bed92d Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sat, 16 May 2020 15:15:57 +0100 Subject: [PATCH 1/8] Add a dbg macro for easy var dumping --- src/boot/boot.janet | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 325893fc..87ea307e 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -945,6 +945,22 @@ (array/push parts (tuple apply f $args))) (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 -> "Threading macro. Inserts x as the second value in the first form in forms, and inserts the modified first form into the second form From 59302d4f420c2e940aa8a55ba077251a593cf81c Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sat, 16 May 2020 15:42:16 +0100 Subject: [PATCH 2/8] Return dbg values to work inside complex exprs --- src/boot/boot.janet | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 87ea307e..415481e7 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -950,16 +950,23 @@ 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))) + (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) + (case (length ,results) + 0 nil + 1 (,results 0) + ,results)))) (defmacro -> "Threading macro. Inserts x as the second value in the first form From ca3dac7e87ca631af135d5b5cca3a8fd83f9ba83 Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sat, 16 May 2020 15:50:47 +0100 Subject: [PATCH 3/8] Return an immutable tuple instead --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 415481e7..1be6f4be 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -966,7 +966,7 @@ (case (length ,results) 0 nil 1 (,results 0) - ,results)))) + (tuple ;,results))))) (defmacro -> "Threading macro. Inserts x as the second value in the first form 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 4/8] 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) From fb491f0d7c1261d55db7f9b977925046f90910cb Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sun, 17 May 2020 08:12:54 +0100 Subject: [PATCH 5/8] Put back erroneously deleted "Literal" --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 74303769..10b7a577 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -957,7 +957,7 @@ ,;(map (fn [form] (def preface (if (symbol? form) (string form " is") - "is")) + "Literal is")) ~(do (def ,var ,form) (eprintf (string "%s " (dyn :pretty-format "%q")) From e0130e7fd7261c5673e3c1d08650b71e3f45e84e Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Sun, 17 May 2020 08:18:44 +0100 Subject: [PATCH 6/8] "Literal" -> "Expression" for trace-pp msg --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 10b7a577..0e67a1d9 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -957,7 +957,7 @@ ,;(map (fn [form] (def preface (if (symbol? form) (string form " is") - "Literal is")) + "Expression is")) ~(do (def ,var ,form) (eprintf (string "%s " (dyn :pretty-format "%q")) From e9a5cfaddd96ead57eb281816bec69930d7b197d Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Mon, 18 May 2020 21:55:21 +0100 Subject: [PATCH 7/8] Adopt Andrew Chamber's suggestions --- src/boot/boot.janet | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 0e67a1d9..8da45a6a 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -945,7 +945,7 @@ (array/push parts (tuple apply f $args))) (tuple 'fn (tuple '& $args) (tuple/slice parts 0))) -(defmacro trace-pp +(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 @@ -955,13 +955,12 @@ ~(do (def ,results @[]) ,;(map (fn [form] - (def preface (if (symbol? form) - (string form " is") - "Expression is")) ~(do (def ,var ,form) - (eprintf (string "%s " (dyn :pretty-format "%q")) - ,preface + (eprintf (string (dyn :pretty-format "%q") + " is " + (dyn :pretty-format "%q")) + ',form ,var) (eflush) (array/push ,results ,var))) From b1ed5b07077bdfbd05af85949daaf9492bf6fbaf Mon Sep 17 00:00:00 2001 From: LouisJackman <11330428+LouisJackman@users.noreply.github.com> Date: Mon, 18 May 2020 22:02:56 +0100 Subject: [PATCH 8/8] Add "trace " prefix missed out from previous commit --- src/boot/boot.janet | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 8da45a6a..a9ad6fbd 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -957,7 +957,8 @@ ,;(map (fn [form] ~(do (def ,var ,form) - (eprintf (string (dyn :pretty-format "%q") + (eprintf (string "trace " + (dyn :pretty-format "%q") " is " (dyn :pretty-format "%q")) ',form