Implemented and and or as macros.
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 6 Nov 2016 05:06:06 +0000 (18:06 +1300)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 6 Nov 2016 05:06:06 +0000 (18:06 +1300)
scheme-library.scm

index ffe02ea..aad91f4 100644 (file)
                 (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)