src/utilities.lisp: Add new anaphoric `aand'.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 Jun 2018 18:58:28 +0000 (19:58 +0100)
doc/SYMBOLS
doc/misc.tex
src/utilities.lisp

index f6ece85..74dbead 100644 (file)
@@ -2172,6 +2172,7 @@ cl:print-object
 Package `sod-utilities'
 
 utilities.lisp
+  aand                                          macro
   acase                                         macro
   acond                                         macro
   aecase                                        macro
index d672d42..87ddf4d 100644 (file)
@@ -76,6 +76,9 @@ These symbols are defined in the @|sod-utilities| package.
 \begin{describe}{mac}{aif @<condition> @<consequent> @[@<alt>@]}
 \end{describe}
 
+\begin{describe}{mac}{aand @<form>^*}
+\end{describe}
+
 \begin{describe}{mac}{awhen @<condition> @<form>^*}
 \end{describe}
 
index 6663441..4b0eeba 100644 (file)
   "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.