From ea38605427a98112b69a9dd89b1645e030d921ca Mon Sep 17 00:00:00 2001 From: Alexander Griffith Date: Tue, 14 Sep 2021 01:11:55 -0400 Subject: [PATCH] Introduced sample-macros.fnl to demonstrate how import-macros works. --- mode-intro.fnl | 5 ++++- sample-macros.fnl | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 sample-macros.fnl diff --git a/mode-intro.fnl b/mode-intro.fnl index 794b102..e042c98 100644 --- a/mode-intro.fnl +++ b/mode-intro.fnl @@ -1,3 +1,5 @@ +(import-macros {: incf} :sample-macros) + (var counter 0) (var time 0) @@ -8,7 +10,8 @@ (if (< counter 65535) (set counter (+ counter 1)) (set counter 0)) - (set time (+ time dt)) + (incf time dt) + ;;(set time (+ time dt)) (when (> time 3) (love.event.quit))) :keypressed (fn keypressed [key set-mode] diff --git a/sample-macros.fnl b/sample-macros.fnl new file mode 100644 index 0000000..0556551 --- /dev/null +++ b/sample-macros.fnl @@ -0,0 +1,13 @@ +(fn incf [value ?by] + `(set ,value (+ ,value (or ,?by 1)))) + +(fn decf [value ?by] + `(set ,value (+ ,value (or ,?by 1)))) + +(fn with [t keys ?body] + `(let [,keys ,t] + (if ,?body + ,?body + ,keys))) + +{: incf : decf : with}