emacs.d/clones/colinallen.dnsalias.org/lp/node19.html

45 lines
1.8 KiB
HTML
Raw Normal View History

2022-08-02 12:34:59 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE> Using Your Own Definitions in New Functions</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Using Your Own Definitions in New Functions">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node20.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
<A HREF="node15.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
<A HREF="node18.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
<A HREF="lp.html"><B>Contents</B></A>
<B> Next:</B>
<A HREF="node20.html"> Functions with Extended </A>
<B>Up:</B>
<A HREF="node15.html"> Defining Lisp functions</A>
<B> Previous:</B>
<A HREF="node18.html"> Using an Editor</A>
<BR> <HR> <P>
<H1> Using Your Own Definitions in New Functions</H1>
<P>
User-defined functions can be included in new function definitions. For example:
<BLOCKQUOTE>
<PRE>&gt; (defun fourth-power (x)
(square (square x)))
FOURTH-POWER
&gt; (fourth-power 2)
16
</PRE>
</BLOCKQUOTE>
It is worth paying attention to what happens when fourth-power is called. During the computation, the variable ``x'' gets assigned as many as four times. First, x is bound to 2, which is its local value for the function fourth-power. Fourth-power evaluates (square (square 2)), which means that square is called once with the argument 2, and again with the argument 4. Each time square is called, a local version of x is bound to the appropriate value. Finally, x is restored to whatever global value it previously had.
<P>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>