From: Tim Vaughan Date: Sun, 6 Nov 2016 08:41:33 +0000 (+1300) Subject: Fixed AND and OR implementations X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=a95efe1cb2d3774471bb9c0fe4628abe09032ca6;p=scheme.forth.jl.git Fixed AND and OR implementations --- diff --git a/scheme-library.scm b/scheme-library.scm index aad91f4..f95ed65 100644 --- a/scheme-library.scm +++ b/scheme-library.scm @@ -90,16 +90,18 @@ ; and (define (expand-and-expressions expressions) - (if (null? expressions) - #t - (let ((first (car expressions)) - (rest (cdr expressions))) + (let ((first (car expressions)) + (rest (cdr expressions))) + (if (null? rest) + first `(if ,first ,(expand-and-expressions rest) #f)))) (define-macro (and . expressions) - (expand-and-expressions expressions)) + (if (null? expressions) + #t + (expand-and-expressions expressions))) ; or @@ -107,10 +109,12 @@ (if (null? expressions) #f (let ((first (car expressions)) - (rest (cdr expressions))) - `(if ,first - #t - ,(expand-or-expressions rest))))) + (rest (cdr expressions)) + (val (gensym))) + `(let ((,val ,first)) + (if ,val + ,val + ,(expand-or-expressions rest)))))) (define-macro (or . expressions) (expand-or-expressions expressions))