From d8c47d9f0bc7fc12776abcff898b7d1c39cf4d93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Mon, 6 May 2013 13:29:51 +0100 Subject: [PATCH] Better COND --- src/boot.lisp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index ccb6f9b..0b58676 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -163,17 +163,22 @@ ,result)))) (defmacro cond (&rest clausules) - (if (null clausules) - nil - (if (eq (caar clausules) t) - `(progn ,@(cdar clausules)) - (let ((test-symbol (gensym))) - `(let ((,test-symbol ,(caar clausules))) - (if ,test-symbol - ,(if (null (cdar clausules)) - test-symbol - `(progn ,@(cdar clausules))) - (cond ,@(cdr clausules)))))))) + (unless (null clausules) + (destructuring-bind (condition &body body) + (first clausules) + (cond + ((eq condition t) + `(progn ,@body)) + ((null body) + (let ((test-symbol (gensym))) + `(let ((,test-symbol ,condition)) + (if ,test-symbol + ,test-symbol + (cond ,@(rest clausules)))))) + (t + `(if ,condition + (progn ,@body) + (cond ,@(rest clausules)))))))) (defmacro case (form &rest clausules) (let ((!form (gensym))) -- 1.7.10.4