Can you please explain the differences between the three symbols proclaim
, declaim
and declare
?
1 Answers
They are symbols, not keywords.
proclaim
names a function for making global declarations. You should usedeclaim
instead whenever possible.declaim
names a macro for making global declarations (likeproclaim
) which are also effective at compile-time.declare
is just a symbol (i.e., it does not name a function, macro, or special operator) for making local declarations in the beginning of some forms (you can view it as an element of syntax of those forms).
So, the first two affect the global environment and the last one is local.
declaim
is preferable over proclaim
because it has an immediate effect in the compilation environment:
Although the execution of a
proclaim
form has effects that might affect compilation, the compiler does not make any attempt to recognize and specially process proclaim forms. A proclamation such as the following, even if a top level form, does not have any effect until it is executed:
(proclaim '(special *x*))
If compile time side effects are desired,
eval-when
may be useful. For example:
(eval-when (:execute :compile-toplevel :load-toplevel) (proclaim '(special *x*)))
In most such cases, however, it is preferrable to use
declaim
for this purpose.
I.e., if your code is
(proclaim '(special *x*))
(defun foo () (print *x*))
the compiler will complain that foo
reads an unknown special variable *x*
, while
(declaim (special *x*))
(defun foo () (print *x*))
will cause no warnings.
PS. If you are wondering why CL even has proclaim
: first, historically it was there before declaim
, and, second, proclaim
is simpler and more useful in macros.

- 58,617
- 29
- 161
- 278
-
1Thank you sds! Could you clarify the difference between `proclaim` and `declaim`? I have changed the word "keyword" in my question, it was confusing. I was trying to explicitely hide the kind of symbol, but the word symbol was just as fine. – tuscland Feb 12 '13 at 06:59
-
The difference between them is just that: one is a function and, ordinarily, has no effect at compilation time, while the other is a macro which affects the compilation environment. You really need to read the spec for details. – sds Feb 12 '13 at 13:26
-
Alright, I get it now, thanks. Honestly the [Hyperspec](http://clhs.lisp.se/Body/f_procla.htm) is a bit hard to understand, but I will try to refer to it in the future. – tuscland Feb 12 '13 at 13:30
-
The spec is the reference; it is best to start with a textbook, like Graham's ANSI CL or Seibel's Practical CL. – sds Feb 12 '13 at 14:32
-
2sds: you have written some great answers to other questions in the past, and while your summary of the nature of proclaim, declaim and declare are very true, the rest of the answer boils down to read a book or read the hyperspec. I was pretty excited to see the answer to this question as, while I use declaim, I don't have a good intuition of its behaviour and I find the hyperspec's info on the subject is a little dense. Any chance you could expand this answer to include the behaviour of the functions & macros in question? Thanks – Baggers Feb 13 '13 at 12:39
-
1@Baggers, thanks this is exactly the reason why I asked this question, and thanks to sds for enriching it. – tuscland Feb 28 '13 at 07:32