80 lines
4.2 KiB
HTML
80 lines
4.2 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>2.13. Functions</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Functions">
|
|
<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=tex2html1999 HREF="node41.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1997 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1991 HREF="node39.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2001 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2002 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2000 HREF="node41.html"> Unreadable Data Objects</A>
|
|
<B>Up:</B> <A NAME=tex2html1998 HREF="node15.html"> Data Types</A>
|
|
<B> Previous:</B> <A NAME=tex2html1992 HREF="node39.html"> Structures</A>
|
|
<HR> <P>
|
|
<H1><A NAME=SECTION006130000000000000000>2.13. Functions</A></H1>
|
|
<P>
|
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
|
<A NAME=FUNCTIONTYPESECTION>A</A>
|
|
<i>function</i> is anything that may be correctly given to the <tt>funcall</tt>
|
|
or <tt>apply</tt> function, and is
|
|
to be executed as code when arguments are supplied.
|
|
<P>
|
|
A <i>compiled-function</i> is a compiled code object.
|
|
<P>
|
|
A lambda-expression
|
|
(a list whose <i>car</i> is the symbol <tt>lambda</tt>) may serve as a function.
|
|
Depending on the implementation, it may be possible for other lists to
|
|
serve as functions. For example, an implementation might choose to
|
|
represent a ``lexical closure'' as a list whose <i>car</i> contains some
|
|
special marker.
|
|
<P>
|
|
A symbol may serve as a function; an attempt to invoke a symbol as a function
|
|
causes the contents of the symbol's function cell to be used.
|
|
See <tt>symbol-function</tt> and <tt>defun</tt>.
|
|
<P>
|
|
The result of evaluating a <tt>function</tt> special form
|
|
will always be a function.
|
|
<br><img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
|
<P>
|
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
|
X3J13 voted in June 1988 (FUNCTION-TYPE) <A NAME=1363> </A>
|
|
to revise these specifications. The type <tt>function</tt> is to be disjoint
|
|
from <tt>cons</tt> and <tt>symbol</tt>, and so a list whose <i>car</i> is <tt>lambda</tt>
|
|
is not, properly speaking, of type <tt>function</tt>, nor is any symbol.
|
|
However,
|
|
standard Common Lisp functions that accept functional arguments
|
|
will accept a symbol or a list whose <i>car</i> is <tt>lambda</tt>
|
|
and automatically coerce it to be a function; such standard
|
|
functions include <tt>funcall</tt>, <tt>apply</tt>, and <tt>mapcar</tt>.
|
|
Such functions do not, however, accept a lambda-expression as a functional
|
|
argument; therefore one may not write
|
|
<P>
|
|
<P><pre>
|
|
(mapcar '(lambda (x y) (sqrt (* x y))) p q)
|
|
</pre><P>
|
|
but instead one must write something like
|
|
<P><pre>
|
|
(mapcar #'(lambda (x y) (sqrt (* x y))) p q)
|
|
</pre><P>
|
|
<P>
|
|
This change makes it impermissible to represent a lexical closure
|
|
as a list whose <i>car</i> is some special marker.
|
|
<P>
|
|
The value of a <tt>function</tt> special form
|
|
will always be of type <tt>function</tt>.
|
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html1999 HREF="node41.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1997 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1991 HREF="node39.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html2001 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html2002 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html2000 HREF="node41.html"> Unreadable Data Objects</A>
|
|
<B>Up:</B> <A NAME=tex2html1998 HREF="node15.html"> Data Types</A>
|
|
<B> Previous:</B> <A NAME=tex2html1992 HREF="node39.html"> Structures</A>
|
|
<HR> <P>
|
|
<HR>
|
|
<P><ADDRESS>
|
|
AI.Repository@cs.cmu.edu
|
|
</ADDRESS>
|
|
</BODY>
|