chiark / gitweb /
Fix constant-resetting.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Apr 2008 09:32:08 +0000 (10:32 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 14 Apr 2008 09:32:08 +0000 (10:32 +0100)
There's a new macro defconstant* which checks a predicate before
actually resetting.  But alas the only offender is in infix.lisp, for
which we have a policy of not requiring external dependencies, so I've
expanded the macro by hand.

infix.lisp
mdw-base.lisp

index 64a0a308d257c0cac310562bb6f81545c597a56f..a77f51ea2c4fc56a6aa6b7e7add96d5efe92dda4 100644 (file)
@@ -94,8 +94,12 @@ (defvar *paren-depth* 0
 ;;;--------------------------------------------------------------------------
 ;;; The tokenizer.
 
-(defconstant eof (cons :eof nil)
-  "A magical object which `get-token' returns at end-of-file.")
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (let ((value (cons :eof nil)))
+    (unless (and (boundp 'eof)
+                (equal (symbol-value 'eof) value))
+      (defconstant eof (cons :eof nil)
+       "A magical object which `get-token' returns at end-of-file."))))
 
 (defun default-get-token ()
   "Read a token from *stream* and store it in *token*."
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