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:   
 
( function [ arg-typespec [ value-typespec ]] )  
 
arg-typespec ::= ( { typespec }*  
                
[ &optional { typespec }*]  
                
[ &rest typespec ]  
                
[ &key { ( keyword typespec ) }*] )  
 

ARGUMENTS and VALUES

typespec—a type specifier .    

value-typespec—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 value-type. 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 (keyword type). 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 value-type can be a values type specifier in order to indicate the types of multiple values.  

Consider a declaration of the following form:  

    (ftype (function (arg0-type arg1-type ...) val-type) f))    

Any form (f arg0 arg1 ...) within the scope of that declaration is equivalent to the following:  

    (the val-type (f (the arg0-type arg0)   
                       (
the arg1-type arg1)  
                       
...))    

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 (arg0-type arg1-type ...) val-type)  
           
fn-valued-variable)  

This declaration has the interpretation that, within the scope of the declaration, the consequences are unspecified if the value of fn-valued-variable is called with arguments not of the specified types; the value resulting from a valid call will be of type val-type.  

As with variable type declarations, nested declarations imply intersections of types, as follows:

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.