Skip to main content

proclaim

proclaim Function

Syntax:

proclaim declaration-specifier ! implementation-dependent

Arguments and Values:

declaration-specifier—a declaration specifier .

Description:

Establishes the declaration specified by declaration-specifier in the global environment.

Such a declaration, sometimes called a global declaration or a proclamation, is always in force unless locally shadowed.

Names of variables and functions within declaration-specifier refer to dynamic variables and global function definitions, respectively.

Figure 3–22 shows a list of declaration identifiers that can be used with proclaim.

Figure 3–22. Global Declaration Specifiers
**declaration inline optimize type ftype notinline special**

An implementation is free to support other (implementation-defined) declaration identifiers as well.

Examples:

(defun declare-variable-types-globally (type vars) 
(proclaim(type ,type ,@vars))
type)
;; Once this form is executed, the dynamic variable \*TOLERANCE\*
;; must always contain a float.
(declare-variable-types-globally ’float ’(\*tolerance\*))
*!* FLOAT

See Also:

declaim, declare, Section 3.2 (Compilation)

Notes:

Although the execution of a proclaim form has e↵ects that might a↵ect 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 e↵ect until it is executed:

(proclaim ’(special *x*))

If compile time side e↵ects 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.

Since proclaim forms are ordinary function forms, macro forms can expand into them.

Expanded Reference: proclaim

Declaring a Special Variable

proclaim establishes global declarations. A common use is to declare a variable special (dynamically scoped).

(proclaim '(special *my-global*))

(setq *my-global* 42)
=> 42

*my-global*
=> 42

Declaring Type Information

(proclaim '(type integer *count*))
;; Now *count* is proclaimed to always hold an integer.

Declaring Optimization Settings

(proclaim '(optimize (speed 3) (safety 1)))
;; Globally sets optimization preferences.

proclaim vs. declaim

proclaim is a function, so its argument is evaluated. This means it takes effect at run time rather than compile time. For compile-time declarations, use declaim or wrap proclaim in eval-when.

;; This proclamation does NOT take effect at compile time:
(proclaim '(special *late-var*))

;; To get compile-time effect, use eval-when:
(eval-when (:compile-toplevel :load-toplevel :execute)
(proclaim '(special *early-var*)))