Added delete-from-plist, delete-from-plistf, remove-from-plistf.
[alexandria.git] / definitions.lisp
blobb1667c2fcbc2617ff70c66d10a548d6cbb3a7229
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."
13 `(defconstant ,name
14 (let ((new ,initial-value))
15 (if (boundp ',name)
16 (let ((old (symbol-value ',name)))
17 (cond
18 ((constantp ',name)
19 (cond
20 ((,test old new)
21 old)
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)
27 new)))
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)
32 new)))
33 new))
34 ,@(when documentation `(,documentation))))