From: Tamas Papp
Subject: handle condition when redefining constants
Date: 
Message-ID: <87d4ykaepi.fsf@pu100877.student.princeton.edu>
When I redefine constants (eg when reloading a package I am working
on), SBCL complains.  From [1] I understand that the complaint is
legitimate, but I would like to avoid it. 

My (automatically generated) Lisp file looks like this [2]:

(defstruct rgb-color red green blue)

(defmacro define-rgb-color (name red green blue)
   `(progn
      (defconstant ,name (make-rgb-color :red ,red :green ,green :blue ,blue))
      (export ',name)))

(define-rgb-color +snow+ 1.0d0 0.9803921568627451d0 0.9803921568627451d0)
(define-rgb-color +ghostwhite+ 0.9725490196078431d0 0.9725490196078431d0 1.0d0)
... (more than 650 definitions)

The SBCL manual suggests that "the programmer can handle the condition
type sb-ext:defconstant-uneql, and choose either the continue or abort
restart as appropriate".  I am still working on understanding
conditions, could someone help me out with this so I could wrap the
whole file in some expression which would suppress the warnings?

Thanks,

Tamas

[1] http://www.sbcl.org/manual/Defining-Constants.html
[2] Yes, I know, exports should be in the defsystem, all in one place,
but I every other export is there except the list of named colors,
which is in a single file.

From: Zach Beane
Subject: Re: handle condition when redefining constants
Date: 
Message-ID: <m3wsws64ap.fsf@unnamed.xach.com>
Tamas Papp <······@gmail.com> writes:

> The SBCL manual suggests that "the programmer can handle the condition
> type sb-ext:defconstant-uneql, and choose either the continue or abort
> restart as appropriate".  I am still working on understanding
> conditions, could someone help me out with this so I could wrap the
> whole file in some expression which would suppress the warnings?

That suggestion comes last. The previous suggestions are probably
easier to use, particularly:

  (defmacro define-constant (name value &optional doc)
    `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
       ,@(when doc (list doc))))

Zach
From: Thomas F. Burdick
Subject: Re: handle condition when redefining constants
Date: 
Message-ID: <1185143494.451921.224930@g4g2000hsf.googlegroups.com>
On Jul 22, 1:55 pm, Zach Beane <····@xach.com> wrote:
> Tamas Papp <······@gmail.com> writes:
> > The SBCL manual suggests that "the programmer can handle the condition
> > type sb-ext:defconstant-uneql, and choose either the continue or abort
> > restart as appropriate".  I am still working on understanding
> > conditions, could someone help me out with this so I could wrap the
> > whole file in some expression which would suppress the warnings?
>
> That suggestion comes last. The previous suggestions are probably
> easier to use, particularly:
>
>   (defmacro define-constant (name value &optional doc)
>     `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
>        ,@(when doc (list doc))))

Or even better, instead of (boundp ',name) use something like (and
(boundp ',name) (equal (symbol-value ',name) ,value))