chiark / gitweb /
Fix constant-resetting.
[lisp] / mdw-base.lisp
index 2c1a79c2286cf539e13c48b10ba27b030a59f5f1..a41b685ba62d601945f74d6ca798dcd0faa1b33a 100644 (file)
@@ -135,6 +135,17 @@ (defun whitespace-char-p (ch)
        t)
     (t nil)))
 
+(defmacro defconstant* (name value &key doc test)
+  "Define a constant, like `defconstant'.  The TEST is an equality test used
+   to decide whether to override the current definition, if any."
+  (let ((temp (gensym)))
+    `(eval-when (:compile-toplevel :load-toplevel :execute)
+       (let ((,temp ,value))
+        (unless (and (boundp ',name)
+                     (funcall ,(or test ''eql) (symbol-value ',name) ,temp))
+          (defconstant ,name ,value ,@(and doc (list doc))))
+        ',name))))
+
 (declaim (ftype (function nil ()) slot-unitialized))
 (defun slot-uninitialized ()
   "A function which signals an error.  Can be used as an initializer form in