chiark / gitweb /
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 f6ece85c298de125d909e981a13f7d17fc52fbce..74dbead437c07e7aeab66f443531d41f4a761c5e 100644 (file)
@@ -2172,6 +2172,7 @@ cl:print-object
 Package `sod-utilities'
 
 utilities.lisp
+  aand                                          macro
   acase                                         macro
   acond                                         macro
   aecase                                        macro
index d672d42be577b28c30984c85216cc64499a62601..87ddf4d6f7e5d746333f9fee2bffc508809e1936 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 6663441df78e75579308a04c95360d123ff5843b..4b0eeba3cad08b286bca7d4d5271878178c841a1 100644 (file)
@@ -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.