1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/s_fn.htm
2024-04-01 10:24:07 +02:00

66 lines
6.8 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: Special Operator 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="f_funcal.htm">
<LINK REL=UP HREF="c_data_a.htm">
<LINK REL=NEXT HREF="f_fn_lam.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="f_funcal.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_data_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_fn_lam.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="function"><I>Special Operator</I> <B>FUNCTION</B></A> <P>
<P>
<P><B>Syntax:</B><P>
<P>
<B>function</B> <I>name</I> =&gt; <I>function</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>name</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> or <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A>. <P>
<I>function</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<P><B>Description:</B><P>
<P>
The <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="#function"><B>function</B></A> is the <A REL=DEFINITION HREF="26_glo_f.htm#functional_value"><I>functional value</I></A> of <I>name</I> in the current <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A>. <P>
If <I>name</I> is a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A>, the functional definition of that name is that established by the innermost lexically enclosing <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A>, <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A>, or <A REL=DEFINITION HREF="s_flet_.htm#macrolet"><B>macrolet</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>, if there is one. Otherwise the global functional definition of the <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> is returned. <P>
If <I>name</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A>, then a <A REL=DEFINITION HREF="26_glo_l.htm#lexical_closure"><I>lexical closure</I></A> is returned. In situations where a <A REL=DEFINITION HREF="26_glo_c.htm#closure"><I>closure</I></A> over the same set of <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A> might be produced more than once, the various resulting <A REL=DEFINITION HREF="26_glo_c.htm#closure"><I>closures</I></A> might or might not be <A REL=DEFINITION HREF="f_eq.htm#eq"><B>eq</B></A>. <P>
It is an error to use <A REL=DEFINITION HREF="#function"><B>function</B></A> on a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> that does not denote a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> in the lexical environment in which the <A REL=DEFINITION HREF="#function"><B>function</B></A> form appears. Specifically, it is an error to use <A REL=DEFINITION HREF="#function"><B>function</B></A> on a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> that denotes a <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> or <A REL=DEFINITION HREF="26_glo_s.htm#special_form"><I>special form</I></A>. An implementation may choose not to signal this error for performance reasons, but implementations are forbidden from defining the failure to signal an error as a useful behavior. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(defun adder (x) (function (lambda (y) (+ x y))))
</PRE>
</TT> The result of <TT>(adder 3)</TT> is a function that adds <TT>3</TT> to its argument: <P>
<PRE>
(setq add3 (adder 3))
(funcall add3 5) =&gt; 8
</PRE>
</TT> This works because <A REL=DEFINITION HREF="#function"><B>function</B></A> creates a <A REL=DEFINITION HREF="26_glo_c.htm#closure"><I>closure</I></A> of the <A REL=DEFINITION HREF="26_glo_l.htm#lambda_expression"><I>lambda expression</I></A> that is able to refer to the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> <TT>3</TT> of the variable <TT>x</TT> even after control has returned from the function <TT>adder</TT>. <P>
<P><B>Side Effects:</B> None.
<P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="m_defun.htm#defun"><B>defun</B></A>, <A REL=DEFINITION HREF="f_fdefin.htm#fdefinition"><B>fdefinition</B></A>, <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A>, <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A>, <A REL=DEFINITION HREF="f_symb_1.htm#symbol-function"><B>symbol-function</B></A>, <A REL=CHILD HREF="03_abaa.htm">Section 3.1.2.1.1 (Symbols as Forms)</A>, <A REL=CHILD HREF="02_dhb.htm">Section 2.4.8.2 (Sharpsign Single-Quote)</A>, <A REL=CHILD HREF="22_acm.htm">Section 22.1.3.13 (Printing Other Objects)</A> <P>
<P><B>Notes:</B><P>
<P>
The notation <TT>#'</TT><I>name</I><TT></TT> may be used as an abbreviation for <TT>(function </TT><I>name</I><TT>)</TT>. <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/iss179.htm">FUNCTION-TYPE:X3J13-MARCH-88</A><LI> <A REL=CHILD HREF="../Issues/iss174.htm">FUNCTION-NAME:LARGE</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>