defconstant5.3.2 14
defconstant name initial-value [documentation] → name
name—a symbol; not evaluated.
initial-value—a form; evaluated.
5.3.2 10 documentation—a string; not evaluated.
5.3.2 7defconstant !!! KMP: Maybe use "establishes" here somewhere?causes the global variable named by name to be given a value that is the result of evaluating initial-value. Once \param{name} has been defined using \macref{defconstant}, its value
is constant and cannot be changed by assignment or \term{binding}.
5.1.2 6A constant defined by defconstant can be redefined with defconstant. This sentence added per Barmar: -kmp 28-Dec-90However, 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 I gave different a formal meaning the same as non-EQL. -kmp 1-Jan-91
(non-\funref{eql})value using a subsequent defconstant.
If documentation is supplied, it is attached to name as a documentation string of kind variable.
defconstant normally appears as a top level form, but it is meaningful for it to appear as a non-top-level form. However, the compile-time side effects described below only take place when defconstant appears as a top level form.
5.3.2 8The consequences are undefined if there are any bindings of the variable named by name at the time defconstant is executed or if the value is not eql to the value of initial-value.
5.3.2 9
Once \param{name} has been declared by \macref{defconstant} to be constant,
the consequences are undefined if any further assignment to or \term{binding}
of \param{name} is attempted. The consequences are undefined when constant symbols are rebound as either lexical or dynamic variables. In other words, a reference to a symbol declared with defconstant always refers to its global value.
The side effects of the execution of defconstant must be equivalent to at least the side effects of the execution of the following code:
We explicitly addressed the question of whether DEFCONSTANT must proclaim the variable SPECIAL in issue DEFCONSTANT-SPECIAL; the final decision was that it might or might not. Including such a proclamation here as required behavior is incorrect. --sjl 5 Mar 92 \code (declaim (special \i{name})) (setf (symbol-value '\i{name}) \i{initial-value}) (setf (documentation '\i{name} 'variable) '\i{documentation}) \endcode
(setf (symbol-value 'name) initial-value) (setf (documentation 'name 'variable) 'documentation)
added qualification about top-level-ness --sjl 5 Mar 92If a defconstant form appears as a top level form, the compiler must recognize that name names a constant variable. An implementation may choose to evaluate the value-form at compile time, load time, or both. Therefore, users must ensure that the initial-value can be evaluated at compile time (regardless of whether or not references to name appear in the file) and that it always evaluates to the same value.
Editor: KMP: Does “same value” here mean eql or similar? Reviewer: Moon: Probably depends on whether load time is compared to compile time, or two compiles.
Removed redundant text. --sjl 5 Mar 92 Names of \term{constant variables} defined by \macref{defconstant} become reserved and may not be further assigned to or bound (although they may be redefined by using \macref{defconstant}).
(defconstant this-is-a-constant 'never-changing "for a test") → THIS-IS-A-CONSTANT this-is-a-constant → NEVER-CHANGING (documentation 'this-is-a-constant 'variable) → "for a test" (constantp 'this-is-a-constant) → true
None.
None.
declaim, defparameter, defvar, documentation, proclaim, Section 3.1.2.1.1.3 (Constant Variables), Section 3.2 (Compilation)
None.