SPECIAL(3cl) |
Common Lisp Reference |
SPECIAL(3cl) |
NAME
special – specify variables as dynamic (declaration)
SYNOPSIS
(
special
) |
ARGUMENTS and VALUES
—a symbol.
VALID CONTEXT
declaration or proclamation
BINDING TYPES AFFECTED
variable
DESCRIPTION
Specifies that all of the s named are dynamic. This specifier affects variable bindings and affects references. All variable bindings affected are made to be dynamic bindings, and affected variable references refer to the current dynamic binding. For example:
(defun () ; The binding of the parameter
(declare (special )) ; *mod* is visible to hack1,
( (car ))) ; but not that of thing.
(defun ()
(declare (special )) ; Declare references to *mod*
; within hack1 to be special.
(if (atom )
(cons ( (car )) ( (cdr )))))
A special declaration does not affect inner bindings of a ; the inner bindings implicitly shadow a special declaration and must be explicitly re-declared to be special. special declarations never apply to function bindings.
special declarations can be either bound declarations, affecting both a binding and references, or free declarations, affecting only references, depending on whether the declaration is attached to a variable binding.
When used in a proclamation, a special declaration specifier applies to all bindings as well as to all references of the mentioned variables. For example, after
(declaim (special ))
then in a function definition such as
(defun () )
the parameter is bound as a dynamic variable rather than as a lexical variable.
AFFECTED BY
(none)
EXCEPTIONAL SITUATIONS
(none)
NOTES
(none)
EXAMPLES
(
defun
(
)
; this y is special
(
declare
(
special
))
(
let
((
t
))
; this y is lexical
(
list
(
locally
(
declare
(
special
))
))))
; this y refers to the
; special binding of y
(
nil
)
(
T NIL
)
(
setf
(
symbol-value
’
)
6
)
(
defun
(
x
)
; a lexical binding of x
(
print
)
(
let
((
(
1+
)))
; a special binding of x
(
declare
(
special
))
; and a lexical reference
(
bar
))
(
1+
))
(
defun
()
(
print
(
locally
(
declare
(
special
))
)))
(
10
)
10
11
11
(
setf
(
symbol-value
’
)
6
)
(
defun
(
)
; [1] 1st occurrence of x
(
let
((
)
; [2] 2nd occurrence of x
; -- same as 1st occurrence
(
))
; [3] 3rd occurrence of x
(
declare
(
special
))
(
list
)))
(
’
’
)
(
)
(
defun
(
&optional
(
))
(
declare
(
special
))
)
The reference to *foo* in the first line of this example is not special even though there is a special declaration in the second line.
(
declaim
(
special
))
(
setq
1
1
)
1
(
let
((
2
) (
2
))
; the binding of prosp is special
(
set
’
3
)
; due to the preceding proclamation,
(
set
’
3
)
; whereas the variable reg is lexical
(
list
))
(
3 2
)
(
list
)
(
1 3
)
(
declaim
(
special
))
; x is always special.
(
defun
(
)
(
declare
(
special
))
(
let
((
3
) (
(
*
2
)))
(
print
(
+
(
locally
(
declare
(
special
))
)))
(
let
((
4
))
(
declare
(
special
))
(
))))
In the contorted code above, the outermost and innermost bindings of + are different, one being the value, which is 3, of the lexical variable , and the other being the value of the dynamic variable named (a binding of which happens, coincidentally, to lexically surround it at an outer level). All the bindings of and references to are dynamic, however, because of the proclamation that is always special. are dynamic, but the middle binding is lexical. The two arguments to
SEE ALSO
defparameter(3cl), defvar(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 Thursday 2 March 2017.