From: Tim Vaughan Date: Sun, 6 Nov 2016 05:06:06 +0000 (+1300) Subject: Implemented and and or as macros. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=749dd8439730c404058c7a672252ab19967268ac;p=scheme.forth.jl.git Implemented and and or as macros. --- diff --git a/scheme-library.scm b/scheme-library.scm index ffe02ea..aad91f4 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -87,6 +87,35 @@ (error "cond requires at least one clause.") (expand-clauses clauses))) +; and + +(define (expand-and-expressions expressions) + (if (null? expressions) + #t + (let ((first (car expressions)) + (rest (cdr expressions))) + `(if ,first + ,(expand-and-expressions rest) + #f)))) + +(define-macro (and . expressions) + (expand-and-expressions expressions)) + +; or + +(define (expand-or-expressions expressions) + (if (null? expressions) + #f + (let ((first (car expressions)) + (rest (cdr expressions))) + `(if ,first + #t + ,(expand-or-expressions rest))))) + +(define-macro (or . expressions) + (expand-or-expressions expressions)) + + ;; TESTING (define-macro (backwards . body)