From 3c6fd93b5a6f7e097a6982a344638c1f7f55be55 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 9 Dec 2013 15:37:21 +0900 Subject: [PATCH] add hygienic `case` syntax --- piclib/built-in.scm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 27351492..e13777d0 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -610,3 +610,16 @@ (define (compare x y) (identifier=? use-env x use-env y)) (make-syntactic-closure mac-env '() (unwrap (f (wrap expr) inject compare)))))) + +(define-syntax case + (er-macro-transformer + (lambda (expr inject compare) + (let ((key (cadr expr)) + (clauses (cddr expr))) + `(let ((key ,key)) + ,(let loop ((clauses clauses)) + (if (null? clauses) + '#f + `(if (or ,@(map (lambda (x) `(eqv? key ,x)) (caar clauses))) + ,@(cdar clauses) + ,(loop (cdr clauses))))))))))