53 lines
9.8 KiB
HTML
53 lines
9.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: Section 3.1.2.1.2.3</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="03_ababb.htm">
|
|
<LINK REL=UP HREF="03_abab.htm">
|
|
<LINK REL=NEXT HREF="03_ababd.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="03_ababb.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_abab.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_ababd.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
3.1.2.1.2.3 Function Forms</H2> <P>
|
|
If the <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operator</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A> naming a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>, the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> represents a <A REL=DEFINITION HREF="26_glo_f.htm#function_form"><I>function form</I></A>, and the <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdr</I></A> of the list contains the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> which when evaluated will supply the arguments passed to the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. <P>
|
|
When a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> is not defined, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_undefi.htm#undefined-function"><B>undefined-function</B></A> should be signaled at run time; see <A REL=CHILD HREF="03_bbc.htm">Section 3.2.2.3 (Semantic Constraints)</A>. <P>
|
|
A <A REL=DEFINITION HREF="26_glo_f.htm#function_form"><I>function form</I></A> is evaluated as follows: <P>
|
|
The <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A> in the <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdr</I></A> of the original <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> are evaluated in left-to-right order in the current lexical and dynamic <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environments</I></A>. The <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A> of each such <A REL=DEFINITION HREF="26_glo_e.htm#evaluation"><I>evaluation</I></A> becomes an <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> to the named <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>; any additional <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> returned by the <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A> are discarded. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_f.htm#functional_value"><I>functional value</I></A> of the <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operator</I></A> is retrieved from the <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A>, and that <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> is invoked with the indicated arguments. <P>
|
|
Although the order of <A REL=DEFINITION HREF="26_glo_e.htm#evaluation"><I>evaluation</I></A> of the <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A> themselves is strictly left-to-right, it is not specified whether the definition of the <A REL=DEFINITION HREF="26_glo_o.htm#operator"><I>operator</I></A> in a <A REL=DEFINITION HREF="26_glo_f.htm#function_form"><I>function form</I></A> is looked up before the <A REL=DEFINITION HREF="26_glo_e.htm#evaluation"><I>evaluation</I></A> of the <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A>, after the <A REL=DEFINITION HREF="26_glo_e.htm#evaluation"><I>evaluation</I></A> of the <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A>, or between the <A REL=DEFINITION HREF="26_glo_e.htm#evaluation"><I>evaluation</I></A> of any two <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subforms</I></A> if there is more than one such <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subform</I></A>. For example, the following might return 23 or 24. <P>
|
|
<PRE>
|
|
(defun foo (x) (+ x 3))
|
|
(defun bar () (setf (symbol-function 'foo) #'(lambda (x) (+ x 4))))
|
|
(foo (progn (bar) 20))
|
|
</PRE>
|
|
</TT> <P>
|
|
A <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> can be <I>established</I> in one of several ways. A <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> in the <A REL=DEFINITION HREF="26_glo_g.htm#global_environment"><I>global environment</I></A> can be <I>established</I> by <A REL=DEFINITION HREF="m_defun.htm#defun"><B>defun</B></A>, <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> of <A REL=DEFINITION HREF="f_fdefin.htm#fdefinition"><B>fdefinition</B></A>, <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> of <A REL=DEFINITION HREF="f_symb_1.htm#symbol-function"><B>symbol-function</B></A>, <A REL=DEFINITION HREF="f_ensure.htm#ensure-generic-function"><B>ensure-generic-function</B></A>, <A REL=DEFINITION HREF="m_defmet.htm#defmethod"><B>defmethod</B></A> (implicitly, due to <A REL=DEFINITION HREF="f_ensure.htm#ensure-generic-function"><B>ensure-generic-function</B></A>), or <A REL=DEFINITION HREF="m_defgen.htm#defgeneric"><B>defgeneric</B></A>. A <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_f.htm#function_name"><I>function name</I></A> in the <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> can be <I>established</I> by <A REL=DEFINITION HREF="s_flet_.htm#flet"><B>flet</B></A> or <A REL=DEFINITION HREF="s_flet_.htm#labels"><B>labels</B></A>. <P>
|
|
The next figure lists some <A REL=DEFINITION HREF="26_glo_d.htm#defined_name"><I>defined names</I></A> that are applicable to <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A>. <P>
|
|
<PRE>
|
|
<A REL=DEFINITION HREF="f_apply.htm#apply">apply</A> <A REL=DEFINITION HREF="f_fdefin.htm#fdefinition">fdefinition</A> <A REL=DEFINITION HREF="f_mapc_.htm#mapcan">mapcan</A>
|
|
<A REL=DEFINITION HREF="v_call_a.htm#call-arguments-limit">call-arguments-limit</A> <A REL=DEFINITION HREF="s_flet_.htm#flet">flet</A> <A REL=DEFINITION HREF="f_mapc_.htm#mapcar">mapcar</A>
|
|
<A REL=DEFINITION HREF="f_comple.htm#complement">complement</A> <A REL=DEFINITION HREF="f_fmakun.htm#fmakunbound">fmakunbound</A> <A REL=DEFINITION HREF="f_mapc_.htm#mapcon">mapcon</A>
|
|
<A REL=DEFINITION HREF="f_cons_1.htm#constantly">constantly</A> <A REL=DEFINITION HREF="f_funcal.htm#funcall">funcall</A> <A REL=DEFINITION HREF="f_mapc_.htm#mapl">mapl</A>
|
|
<A REL=DEFINITION HREF="m_defgen.htm#defgeneric">defgeneric</A> <A REL=DEFINITION HREF="a_fn.htm#function">function</A> <A REL=DEFINITION HREF="f_mapc_.htm#maplist">maplist</A>
|
|
<A REL=DEFINITION HREF="m_defmet.htm#defmethod">defmethod</A> <A REL=DEFINITION HREF="f_fnp.htm#functionp">functionp</A> <A REL=DEFINITION HREF="s_multip.htm#multiple-value-call">multiple-value-call</A>
|
|
<A REL=DEFINITION HREF="m_defun.htm#defun">defun</A> <A REL=DEFINITION HREF="s_flet_.htm#labels">labels</A> <A REL=DEFINITION HREF="f_reduce.htm#reduce">reduce</A>
|
|
<A REL=DEFINITION HREF="f_fbound.htm#fboundp">fboundp</A> <A REL=DEFINITION HREF="f_map.htm#map">map</A> <A REL=DEFINITION HREF="f_symb_1.htm#symbol-function">symbol-function</A>
|
|
</PRE>
|
|
<P><B>Figure 3-4. Some function-related defined names</B> <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/iss181.htm">GENERIC-FLET-POORLY-DESIGNED:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss359.htm">WITH-ADDED-METHODS:DELETE</A><LI> <A REL=CHILD HREF="../Issues/iss171.htm">FUNCTION-CALL-EVALUATION-ORDER:MORE-UNSPECIFIED</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>
|