66 lines
4.1 KiB
HTML
66 lines
4.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>5.1.5. Function Calls</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Function Calls">
|
|
<meta name="keywords" value="clm">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<b>Common Lisp the Language, 2nd Edition</b>
|
|
<BR> <HR><A NAME=tex2html2273 HREF="node62.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2271 HREF="node56.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2267 HREF="node60.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2275 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2276 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2274 HREF="node62.html"> Functions</A>
|
|
<B>Up:</B> <A NAME=tex2html2272 HREF="node56.html"> Forms</A>
|
|
<B> Previous:</B> <A NAME=tex2html2268 HREF="node60.html"> Macros</A>
|
|
<HR> <P>
|
|
<H2><A NAME=SECTION00915000000000000000>5.1.5. Function Calls</A></H2>
|
|
<P>
|
|
If a list is to be evaluated as a form and the first element is
|
|
not a symbol that names a special form or macro, then the list
|
|
is assumed to be a <i>function call</i>. The first element of the
|
|
list is taken to name a function. Any and all remaining elements
|
|
of the list are forms to be evaluated; one value is obtained
|
|
from each form,
|
|
and these values become the <i>arguments</i> to the function.
|
|
The function is then <i>applied</i> to the arguments.
|
|
The functional computation normally produces a value,
|
|
but it may instead call for a non-local exit; see <tt>throw</tt>.
|
|
A function that does return may produce no value or several values;
|
|
see <tt>values</tt>.
|
|
If and when the function returns, whatever values it returns
|
|
become the values of the function-call form.
|
|
<P>
|
|
For example, consider the evaluation of the form <tt>(+ 3 (* 4 5))</tt>.
|
|
The symbol <tt>+</tt> names the addition function, not a special form or macro.
|
|
Therefore the two forms <tt>3</tt> and <tt>(* 4 5)</tt> are evaluated to produce
|
|
arguments. The form <tt>3</tt> evaluates to <tt>3</tt>, and the form
|
|
<tt>(* 4 5)</tt> is a function call (to the multiplication function).
|
|
Therefore the forms <tt>4</tt> and <tt>5</tt> are evaluated, producing arguments
|
|
<tt>4</tt> and <tt>5</tt> for the multiplication. The multiplication function
|
|
calculates the number <tt>20</tt> and returns it. The values <tt>3</tt> and <tt>20</tt>
|
|
are then given as arguments to the addition function, which calculates
|
|
and returns the number <tt>23</tt>. Therefore we say <tt>(+ 3 (* 4 5)) => 23</tt>.
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
X3J13 voted in October 1988 (FUNCTION-CALL-EVALUATION-ORDER) <A NAME=3166> </A>
|
|
to clarify that while the arguments in a function call are always
|
|
evaluated in strict left-to-right order, whether the function to
|
|
be called is determined before or after argument evaluation
|
|
is unspecified. Programs are in error
|
|
that rely on a particular order of evaluation
|
|
of the first element of a function call relative to the
|
|
argument forms.
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html2273 HREF="node62.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html2271 HREF="node56.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html2267 HREF="node60.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2275 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2276 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2274 HREF="node62.html"> Functions</A>
|
|
<B>Up:</B> <A NAME=tex2html2272 HREF="node56.html"> Forms</A>
|
|
<B> Previous:</B> <A NAME=tex2html2268 HREF="node60.html"> Macros</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|