From 3570252c1b697f215d9f0611d13ef91ebeffacf0 Mon Sep 17 00:00:00 2001 From: Peter Tillemans Date: Wed, 13 Mar 2024 23:52:40 +0100 Subject: [PATCH] add macros --- 11_extensibility.scm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 11_extensibility.scm diff --git a/11_extensibility.scm b/11_extensibility.scm new file mode 100644 index 0000000..48f29ba --- /dev/null +++ b/11_extensibility.scm @@ -0,0 +1,40 @@ +;; -*- geiser-scheme-implementation: guile -*- + +(if (our-test) + (begin + (do-thing-1) + (do-thing-2))) + +(define (when test . body) + `(if ,test + ,(cons 'begin body))) + +(when '(our-test) + '(do-thing-1) + '(do-thing-2)) + ; (if (our-test) (begin (do-thing-1) (do-thing-2))) + +(define-macro (when test . body) + `(if ,test + ,(cons 'begin body))) + +(when (our-test) + (do-thing-1) + (do-thing-2)) + +(define-syntax-rule (when test body ...) + (if test + (begin body ...))) + +(define-syntax-rule (for (item lst) body ...) + (for-each (lambda (item) + body ...) + lst)) + +(for (str '("strawberries" "bananas" "grapes")) + (display + (string-append "I just love " + (string-upcase str) + "!!!\n"))) + +; #