1 (in-package :alexandria
)
3 (defmacro define-constant
(name initial-value
&key
(test 'eql
) documentation
)
4 "Ensures that the global variable named by NAME is a constant with a value
5 that is equal under TEST to the result of evaluating INITIAL-VALUE. TEST
6 defaults to EQL, and if given it must be a symbol naming a function. If
7 DOCUMENTATION is given, it becomes the documentation string of the constant.
9 Signals an error if NAME is already a bound non-constant variable.
11 Signals an error if NAME is already a constant variable whose value is not
12 equal under TEST to result of evaluating INITIAL-VALUE."
14 (let ((new ,initial-value
))
16 (let ((old (symbol-value ',name
)))
23 (cerror "Try to redefine the constant."
24 "~@<~S is an already defined constant whose value ~
25 ~S is not equal to the provided initial value ~S ~
26 under ~S.~:@>" ',name old new
',test
)
29 (cerror "Try to redefine the variable as a constant."
30 "~@<~S is an already bound non-constant variable ~
31 whose value is ~S.~:@>" ',name old
)
34 ,@(when documentation
`(,documentation
))))