Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"constant is being redefined" with defconstant?

Tags:

common-lisp

I'm reading chapter 5.2 of PAIP. And when I try define a constant using the following form, taken exactly from the book, I get the error shown below. I'm using SBCL 1.1.14.debian as the interpreter. What am I doing wrong?

(defconstant no-bindings '((t . t))
  "Indicates pat-match success, with no variables.")

The constant NO-BINDINGS is being redefined (from (T T) to ((T . T)))

like image 435
flingjie Avatar asked Oct 27 '25 03:10

flingjie


1 Answers

The error means that you have done a previous definition of the same name no-bindings with the value '(T T).

For instance in the REPL you have done a definition:

(defconstant no-bindings '(t  t)
  "Indicates pat-match success, with no variables.")

and then you have redefined no-bindings with:

(defconstant no-bindings '((t . t))
  "Indicates pat-match success, with no variables.")

The manual specifies:

A constant defined by defconstant can be redefined with defconstant. However, the consequences are undefined if an attempt is made to assign a value to the symbol using another operator, or to assign it to a different value using a subsequent defconstant.

Updated

Note that in SBCL, even a double definition of the same value, for instance, writing twice in the REPL:

(defconstant no-bindings '((t . t))
  "Indicates pat-match success, with no variables.")

causes a constant redefinition error, while in other systems (I tried CCL), this does not happen. Actually this is due to the interpretation of "different value" in the above definition. The Glossary says the different is not the same, and same is not eql, and

 (eql '((t . t)) '((t . t)))

gives NIL, while other equality operators, as, for instance:

 (equal '((t . t)) '((t . t)))

returns T.

So, it seems that SBCL follows correctly the formal specification, differently from other systems.

like image 96
Renzo Avatar answered Oct 29 '25 07:10

Renzo