From 634c9e0e2f9e675276468064529a6c226497b1e0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 11 Feb 2014 21:35:56 +0900 Subject: [PATCH] fix #38 --- piclib/built-in.scm | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index ce3ed630..af6e6357 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -85,26 +85,40 @@ (cons (r 'begin) (cdar clauses)) (cons (r 'cond) (cdr clauses))))))))) + (define (single? list) + (if (pair? list) + (null? (cdr list)) + #f)) + (define-syntax and (er-macro-transformer (lambda (expr r compare) (let ((exprs (cdr expr))) - (if (null? exprs) - #t - (list (r 'if) (car exprs) - (cons (r 'and) (cdr exprs)) - #f)))))) + (cond + ((null? exprs) + #t) + ((single? exprs) + (car exprs)) + (else + (list (r 'let) (list (list (r 'it) (car exprs))) + (list (r 'if) (r 'it) + (cons (r 'and) (cdr exprs)) + (r 'it))))))))) (define-syntax or (er-macro-transformer (lambda (expr r compare) (let ((exprs (cdr expr))) - (if (null? exprs) - #f - (list (r 'let) (list (list (r 'it) (car exprs))) - (list (r 'if) (r 'it) - (r 'it) - (cons (r 'or) (cdr exprs))))))))) + (cond + ((null? exprs) + #t) + ((single? exprs) + (car exprs)) + (else + (list (r 'let) (list (list (r 'it) (car exprs))) + (list (r 'if) (r 'it) + (r 'it) + (cons (r 'or) (cdr exprs)))))))))) (define-syntax quasiquote (er-macro-transformer