From e2e45fa91595c5eea275b1c13673db113b132448 Mon Sep 17 00:00:00 2001 From: Andrea Griffini Date: Wed, 1 May 2013 22:26:03 +0200 Subject: [PATCH] added OTHERWISE support to (CASE ...) --- src/boot.lisp | 5 +++-- src/toplevel.lisp | 2 +- tests/conditionals.lisp | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index 1f8db01..d3dc898 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -183,8 +183,9 @@ `(let ((,!form ,form)) (cond ,@(mapcar (lambda (clausule) - (if (eq (car clausule) t) - clausule + (if (or (eq (car clausule) t) + (eq (car clausule) 'otherwise)) + `(t ,@(cdr clausule)) `((eql ,!form ',(car clausule)) ,@(cdr clausule)))) clausules))))) diff --git a/src/toplevel.lisp b/src/toplevel.lisp index c3020c0..c32dfbb 100644 --- a/src/toplevel.lisp +++ b/src/toplevel.lisp @@ -66,7 +66,7 @@ list* list-all-packages listp loop make-array make-package make-symbol mapcar member minusp mod multiple-value-bind multiple-value-call multiple-value-list multiple-value-prog1 - nconc nil not nreconc nth nthcdr null numberp or + nconc nil not nreconc nth nthcdr null numberp or otherwise package-name package-use-list packagep parse-integer plusp pop prin1-to-string print proclaim prog1 prog2 progn psetq push quote read-from-string remove remove-if remove-if-not return diff --git a/tests/conditionals.lisp b/tests/conditionals.lisp index 19736e1..af71104 100644 --- a/tests/conditionals.lisp +++ b/tests/conditionals.lisp @@ -15,3 +15,10 @@ (test (= 2 (cond (1 2)))) (test (= 3 (cond (nil 1) (2 3)))) (test (eql nil (cond (nil 1) (nil 2)))) + +; CASE + +(test (= (case 1 (2 3) (otherwise 42)) 42)) +(test (= (case 1 (2 3) (t 42)) 42)) +(test (= (case 1 (2 3) (1 42)) 42)) +(test (null (case 1 (2 3)))) -- 1.7.10.4