From c34b237da0bb4bf08a3531a2e11442623df7e9d4 Mon Sep 17 00:00:00 2001
Message-Id: <c34b237da0bb4bf08a3531a2e11442623df7e9d4.1719051824.git.mdw@distorted.org.uk>
From: Mark Wooding <mdw@chiark.greenend.org.uk>
Date: Thu, 26 May 2016 09:26:09 +0100
Subject: [PATCH] src/utilities.lisp (defvar-unbound): Make a variable with
 docs and no value.
Organization: Straylight/Edgeware

From: Mark Wooding <mdw@distorted.org.uk>

---
 doc/SYMBOLS        |  1 +
 doc/misc.tex       |  3 +++
 src/utilities.lisp | 11 +++++++++++
 3 files changed, 15 insertions(+)

diff --git a/doc/SYMBOLS b/doc/SYMBOLS
index 43ed0f2..909f993 100644
--- a/doc/SYMBOLS
+++ b/doc/SYMBOLS
@@ -2217,6 +2217,7 @@ utilities.lisp
   default-slot                                  macro
   define-access-wrapper                         macro
   define-on-demand-slot                         macro
+  defvar-unbound                                macro
   designated-condition                          function
   dosequence                                    macro
   sb-mop:eql-specializer                        class
diff --git a/doc/misc.tex b/doc/misc.tex
index 2e7b504..f6037e1 100644
--- a/doc/misc.tex
+++ b/doc/misc.tex
@@ -172,6 +172,9 @@ These symbols are defined in the @|sod-utilities| package.
     {compose @<function> \&rest @<more-functions> @> @<function>}
 \end{describe}
 
+\begin{describe}{mac}{defvar @<name> @<documentation> @> @<name>}
+\end{describe}
+
 \begin{describe}{fun}{symbolicate \&rest @<symbols> @> @<symbol>}
 \end{describe}
 
diff --git a/src/utilities.lisp b/src/utilities.lisp
index 72423fd..72af8b3 100644
--- a/src/utilities.lisp
+++ b/src/utilities.lisp
@@ -708,6 +708,17 @@ (defun compose (function &rest more-functions)
 	       (multiple-value-call func-b (apply func-a args)))))
     (reduce #'compose1 more-functions :initial-value function)))
 
+;;;--------------------------------------------------------------------------
+;;; Variables.
+
+(export 'defvar-unbound)
+(defmacro defvar-unbound (var doc)
+  "Make VAR a special variable with documentation DOC, but leave it unbound."
+  `(eval-when (:compile-toplevel :load-toplevel :execute)
+     (defvar ,var)
+     (setf (documentation ',var 'variable) ',doc)
+     ',var))
+
 ;;;--------------------------------------------------------------------------
 ;;; Symbols.
 
-- 
[mdw]

