FUNCTION(3cl) |
Common Lisp Reference |
FUNCTION(3cl) |
NAME
function – object representing code to be executed when an appropriate number of arguments is supplied (system class)
SYNOPSIS
Compound type specifier kind: specializing.
;; compound type specifier syntax:
|
ARGUMENTS and VALUES
—a type specifier .
—a type specifier .
VALID CONTEXT
n/a
BINDING TYPES AFFECTED
n/a
DESCRIPTION
The list form of the function type-specifier can be used only for declaration and not for discrimination. Every element of this type is a function that accepts arguments of the types specified by the argj-types and returns values that are members of the types specified by . The &optional, &rest, &key, and &allow-other-keys markers can appear in the list of argument types. The type specifier provided with &rest is the type of each actual argument, not the type of the corresponding variable.
The &key parameters should be supplied as lists of the form (). The keyword must be a valid keyword-name symbol as must be supplied in the actual arguments of a call. This is usually a symbol in the KEYWORD package but can be any symbol . When &key is given in a function type specifier lambda list, the keyword parameters given are exhaustive unless &allow-other-keys is also present. &allow-other-keys is an indication that other keyword arguments might actually be supplied and, if supplied, can be used. For example, the type of the function make-list could be declared as follows:
(function ((integer 0) &key (:initial-element t)) list)
The values type specifier in order to indicate the types of multiple values. can be a
Consider a declaration of the following form:
(ftype (function () ) ))
Any form ( ) within the scope of that declaration is equivalent to the following:
(the ( (the )
(the )
))
That is, the consequences are undefined if any of the arguments are not of the specified types or the result is not of the specified type. In particular, if any argument is not of the correct type, the result is not guaranteed to be of the specified type.
Thus, an ftype declaration for a function describes calls to the function, not the actual definition of the function.
Consider a declaration of the following form:
(type (function () )
)
This declaration has the interpretation that, within the scope of the declaration, the consequences are unspecified if the value of is called with arguments not of the specified types; the value resulting from a valid call will be of type .
As with variable type declarations, nested declarations imply intersections of types, as follows:
Consider the following two declarations of ftype:
(ftype (function ( )
) ))
and
(ftype (function ( )
) ))
If both these declarations are in effect, then within the shared scope of the declarations, calls to f can be treated as if f were declared as follows:
(ftype (function ((and )
(and )
)
(and )) ))
It is permitted to ignore one or all of the ftype declarations in force.
If two (or more) type declarations are in effect for a variable, and they are both function declarations, the declarations combine similarly.
AFFECTED BY
(none)
EXCEPTIONAL SITUATIONS
(none)
NOTES
(none)
EXAMPLES
(none)
SEE ALSO
(none)
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 Friday 31 March 2017.