From: Mark Wooding Date: Thu, 26 May 2016 08:26:09 +0000 (+0100) Subject: src/utilities.lisp: Add new anaphoric `aand'. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/3e166443f7ed632f0a8b3d0e680c2afcc265d56f src/utilities.lisp: Add new anaphoric `aand'. --- diff --git a/doc/SYMBOLS b/doc/SYMBOLS index f6ece85..74dbead 100644 --- a/doc/SYMBOLS +++ b/doc/SYMBOLS @@ -2172,6 +2172,7 @@ cl:print-object Package `sod-utilities' utilities.lisp + aand macro acase macro acond macro aecase macro diff --git a/doc/misc.tex b/doc/misc.tex index d672d42..87ddf4d 100644 --- a/doc/misc.tex +++ b/doc/misc.tex @@ -76,6 +76,9 @@ These symbols are defined in the @|sod-utilities| package. \begin{describe}{mac}{aif @ @ @[@@]} \end{describe} +\begin{describe}{mac}{aand @
^*} +\end{describe} + \begin{describe}{mac}{awhen @ @^*} \end{describe} diff --git a/src/utilities.lisp b/src/utilities.lisp index 6663441..4b0eeba 100644 --- a/src/utilities.lisp +++ b/src/utilities.lisp @@ -273,6 +273,22 @@ (defmacro awhen (cond &body body) "If COND, evaluate BODY as a progn with `it' bound to the value of COND." `(let ((it ,cond)) (when it ,@body))) +(export 'aand) +(defmacro aand (&rest forms) + "Like `and', but anaphoric. + + Each FORM except the first is evaluated with `it' bound to the value of + the previous one. If there are no forms, then the result it `t'; if there + is exactly one, then wrapping it in `aand' is pointless." + (labels ((doit (first rest) + (if (null rest) + first + `(let ((it ,first)) + (if it ,(doit (car rest) (cdr rest)) nil))))) + (if (null forms) + 't + (doit (car forms) (cdr forms))))) + (export 'acond) (defmacro acond (&body clauses &environment env) "Like COND, but with `it' bound to the value of the condition.