102 lines
10 KiB
HTML
102 lines
10 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: System Class FUNCTION</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="t_ban.htm">
|
|
<LINK REL=UP HREF="c_types_.htm">
|
|
<LINK REL=NEXT HREF="t_cmpd_f.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="t_ban.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_types_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="t_cmpd_f.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="function"><I>System Class</I> <B>FUNCTION</B></A> <P>
|
|
<P>
|
|
<P><B>Class Precedence List:</B><P>
|
|
<A REL=DEFINITION HREF="#function"><B>function</B></A>, <A REL=DEFINITION HREF="t_t.htm#t"><B>t</B></A> <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
A <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> is an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> that represents code to be executed when an appropriate number of arguments is supplied. A <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> is produced by the <A REL=DEFINITION HREF="s_fn.htm#function"><B>function</B></A> <A REL=DEFINITION HREF="26_glo_s.htm#special_form"><I>special form</I></A>, the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="f_coerce.htm#coerce"><B>coerce</B></A>, or the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="f_cmp.htm#compile"><B>compile</B></A>. A <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> can be directly invoked by using it as the first argument to <A REL=DEFINITION HREF="f_funcal.htm#funcall"><B>funcall</B></A>, <A REL=DEFINITION HREF="f_apply.htm#apply"><B>apply</B></A>, or <A REL=DEFINITION HREF="s_multip.htm#multiple-value-call"><B>multiple-value-call</B></A>. <P>
|
|
<P><B>Compound Type Specifier Kind:</B><P>
|
|
<P>
|
|
Specializing. <P>
|
|
<P><B>Compound Type Specifier Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>function</B> <I>[arg-typespec [value-typespec]]</I><P>
|
|
<P>
|
|
<PRE>
|
|
arg-typespec::= (typespec*
|
|
[&optional typespec*]
|
|
[&rest typespec]
|
|
[&key (keyword typespec)*])
|
|
</PRE>
|
|
<P>
|
|
<P><B>Compound Type Specifier Arguments:</B><P>
|
|
<P>
|
|
<I>typespec</I>---a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>. <P>
|
|
<I>value-typespec</I>---a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>. <P>
|
|
<P><B>Compound Type Specifier Description:</B><P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
The list form of the <A REL=DEFINITION HREF="#function"><B>function</B></A> <I>type-specifier</I> can be used only for declaration and not for discrimination. Every element of this <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> is a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> that accepts arguments of the types specified by the <I>argj-types</I> and returns values that are members of the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A> specified by <I>value-type</I>. The <TT>&optional</TT>, <TT>&rest</TT>, <TT>&key</TT>, and <TT>&allow-other-keys</TT> markers can appear in the list of argument types. The <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> provided with <TT>&rest</TT> is the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of each actual argument, not the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of the corresponding variable. <P>
|
|
The <TT>&key</TT> parameters should be supplied as lists of the form <TT>(</TT><I>keyword</I><TT> </TT><I>type</I><TT>)</TT>. The <I>keyword</I> must be a valid keyword-name symbol as must be supplied in the actual arguments of a call. This is usually a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> in the <TT>KEYWORD</TT> package but can be any <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. When <TT>&key</TT> is given in a <B>function</B> <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> <A REL=DEFINITION HREF="26_glo_l.htm#lambda_list"><I>lambda list</I></A>, the <A REL=DEFINITION HREF="26_glo_k.htm#keyword_parameter"><I>keyword parameters</I></A> given are exhaustive unless <TT>&allow-other-keys</TT> is also present. <TT>&allow-other-keys</TT> is an indication that other keyword arguments might actually be supplied and, if supplied, can be used. For example, the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="f_mk_lis.htm#make-list"><B>make-list</B></A> could be declared as follows: <P>
|
|
<PRE>
|
|
(function ((integer 0) &key (:initial-element t)) list)
|
|
</PRE>
|
|
</TT> <P>
|
|
The <I>value-type</I> can be a <B>values</B> <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> in order to indicate the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A> of <A REL=DEFINITION HREF="26_glo_m.htm#multiple_values"><I>multiple values</I></A>. <P>
|
|
<P>
|
|
Consider a declaration of the following form: <P>
|
|
<PRE>
|
|
(ftype (function (arg0-type arg1-type ...) val-type) f))
|
|
</PRE>
|
|
</TT> <P>
|
|
Any <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> <TT>(f arg0 arg1 ...)</TT> within the scope of that declaration is equivalent to the following: <P>
|
|
<PRE>
|
|
(the val-type (f (the arg0-type arg0) (the arg1-type arg1) ...))
|
|
</PRE>
|
|
</TT> <P>
|
|
That is, the consequences are undefined if any of the arguments are not of the specified <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A> or the result is not of the specified <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. In particular, if any argument is not of the correct <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>, the result is not guaranteed to be of the specified <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. <P>
|
|
Thus, an <A REL=DEFINITION HREF="d_ftype.htm#ftype"><B>ftype</B></A> declaration for a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> describes <A REL=DEFINITION HREF="26_glo_c.htm#call"><I>calls</I></A> to the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>, not the actual definition of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. <P>
|
|
Consider a declaration of the following form: <P>
|
|
<PRE>
|
|
(type (function (arg0-type arg1-type ...) val-type) fn-valued-variable)
|
|
</PRE>
|
|
</TT> <P>
|
|
This declaration has the interpretation that, within the scope of the declaration, the consequences are unspecified if the value of <TT>fn-valued-variable</TT> is called with arguments not of the specified <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A>; the value resulting from a valid call will be of type <TT>val-type</TT>. <P>
|
|
As with variable type declarations, nested declarations imply intersections of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A>, as follows: <P><DL><DT>* Consider the following two declarations of <A REL=DEFINITION HREF="d_ftype.htm#ftype"><B>ftype</B></A>: <P><DD>
|
|
<PRE>
|
|
(ftype (function (arg0-type1 arg1-type1 ...) val-type1) f))
|
|
</PRE>
|
|
</TT> and <P>
|
|
<PRE>
|
|
(ftype (function (arg0-type2 arg1-type2 ...) val-type2) f))
|
|
</PRE>
|
|
</TT> <P>
|
|
If both these declarations are in effect, then within the shared scope of the declarations, calls to <TT>f</TT> can be treated as if <TT>f</TT> were declared as follows: <P>
|
|
<PRE>
|
|
(ftype (function ((and arg0-type1 arg0-type2) (and arg1-type1 arg1-type2 ...) ...)
|
|
(and val-type1 val-type2))
|
|
f))
|
|
</PRE>
|
|
</TT> <P>
|
|
It is permitted to ignore one or all of the <A REL=DEFINITION HREF="d_ftype.htm#ftype"><B>ftype</B></A> declarations in force. <P>
|
|
<DT>* If two (or more) type declarations are in effect for a variable, and they are both <TT>function</TT> declarations, the declarations combine similarly. <P><DD></DL><P>
|
|
<P>
|
|
<P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss176.htm">FUNCTION-TYPE-ARGUMENT-TYPE-SEMANTICS:RESTRICTIVE</A><LI> <A REL=CHILD HREF="../Issues/iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE:ANY</A><LI> <A REL=CHILD HREF="../Issues/iss178.htm">FUNCTION-TYPE-REST-LIST-ELEMENT:USE-ACTUAL-ARGUMENT-TYPE</A><LI> <A REL=CHILD HREF="../Issues/iss177.htm">FUNCTION-TYPE-KEY-NAME:SPECIFY-KEYWORD</A><LI> <A REL=CHILD HREF="../Issues/iss342.htm">SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91</A><LI> <A REL=CHILD HREF="../Issues/iss179.htm">FUNCTION-TYPE:X3J13-MARCH-88</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|