DECLARE(3cl)

Common Lisp Reference

DECLARE(3cl)

 

NAME

declare – symbol preceding one or more declaration specifiers (symbol)    

SYNOPSIS

 

declare { declaration-specifier }*  
 

ARGUMENTS and VALUES

declaration-specifier —a declaration specifier; not evaluated.      

DESCRIPTION

A declare expression, sometimes called a declaration, can occur only at the beginning of the bodies of certain forms; that is, it may be preceded only by other declare expressions, or by a documentation string if the context permits.

A declare expression can occur in a lambda expression or in any of the following forms:     

defgeneric

labels

define-compiler-macro

let

define-method-combination

let*

define-setf-expander

locally

defmacro

macrolet

defmethod

multiple-value-bind

defsetf

pprint-logical-block

deftype

prog

defun

prog*

destructuring-bind

restart-case

do

symbol-macrolet

do*

with-accessors

do-all-symbols

with-hash-table-iterator

do-external-symbols

with-input-from-string

do-symbols

with-open-file

dolist

with-open-stream

dotimes

with-output-to-string

flet

with-package-iterator

handler-case

with-slots


A declare expression can only occur where specified by the syntax of these forms. The consequences of attempting to evaluate a declare expression are undefined. In situations where such expressions can appear, explicit checks are made for their presence and they are never actually evaluated; it is for this reason that they are called “declare expressions” rather than “declare forms.”    

Macro forms cannot expand into declarations; declare expressions must appear as actual subexpressions of the form to which they refer.    

The following declaration identifiers that can be used with declare:  
  

dynamic-extent

ignore

optimize

ftype

inline

special

ignorable

notinline

typ e


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

AFFECTED BY

(none)    

EXCEPTIONAL SITUATIONS

The consequences of trying to use a declare expression as a form to be evaluated are undefined.     

NOTES

(none)     

EXAMPLES

(defun nonsense (k x z)    
   
(foo z x)                    ;First call to foo    
   
(let ((j (foo k x))          ;Second call to foo    
         
(x (* k k)))    
       
(declare (inline foo) (special x z))    
       
(foo x j z)))            ;Third call to foo     

In this example, the inline declaration applies only to the third call to foo, but not to the first or second ones. The special declaration of x causes let to make a dynamic binding for x, and causes the reference to x in the body of let to be a dynamic reference. The reference to x in the second call to foo is a local reference to the second parameter of nonsense. The reference to x in the first call to foo is a local reference, not a special one. The special declaration of z causes the reference to z in the third call to foo to be a dynamic reference; it does not refer to the parameter to nonsense named z, because that parameter binding has not been declared to be special. (The special declaration of z does not appear in the body of defun, but in an inner form, and therefore does not affect the binding of the parameter.)     

SEE ALSO

proclaim(3cl), declaration(3cl), dynamic-extent(3cl), ftype(3cl), ignorable(3cl), ignore(3cl), inline(3cl), notinline(3cl), optimize(3cl), type(3cl)    

AUTHOR and COPYRIGHT

Substantial portions of this page are taken from draft proposed American National Standard for Information Systems—Programming Language—Common Lisp, X3J13/94-101R, Version 15.17R, Fri 12-Aug-1994 6:35pm EDT; no copyright indicated.

Additional clarification and comments by Michael Marking <marking@tatanka.com>, http://www.tatanka.com/software/cl-manpages/; alternatively, https://github.com/wakinyantanka/cl-manpages/. Copyright 2017 Michael Marking as both an original and a derivative work.

Licensed under Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0).

This page last revised Sunday 26 February 2017.