95 lines
2.8 KiB
HTML
95 lines
2.8 KiB
HTML
|
<!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> cond (MACRO)</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" cond (MACRO)">
|
||
|
<meta name="keywords" value="lp">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<A HREF="node88.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
||
|
<A HREF="node72.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
||
|
<A HREF="node86.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="node88.html"> cons (FUNCTION)</A>
|
||
|
<B>Up:</B>
|
||
|
<A HREF="node72.html"> Appendix: Selected Lisp </A>
|
||
|
<B> Previous:</B>
|
||
|
<A HREF="node86.html"> cdr (Function)</A>
|
||
|
<BR> <HR> <P>
|
||
|
<H1> cond (MACRO)</H1>
|
||
|
<P>
|
||
|
<b> Format:</b>
|
||
|
<tt> (cond (<test1> <body1> )</tt>
|
||
|
<tt> (<test2> <body2> )</tt>
|
||
|
<tt> .</tt>
|
||
|
<tt> .</tt>
|
||
|
<tt> (<testN> <bodyN> ))</tt>
|
||
|
<P>
|
||
|
<b> Required arguments:</b>
|
||
|
none
|
||
|
<P>
|
||
|
<b> Optional arguments:</b>
|
||
|
zero or more <tt> (<test> <body> )</tt> clauses
|
||
|
<P>
|
||
|
Here, <tt> <test> </tt> is any Lisp expression. The <tt> <body> </tt> is a sequence of zero or more Lisp expressions.
|
||
|
<P>
|
||
|
Each <tt> <test> </tt> expression is evaluated in turn, until one is
|
||
|
found whose value is non-NIL. For this clause, the sequence of
|
||
|
<tt> <body> </tt> expressions are evaluated and the value of the last
|
||
|
expression is returned as the result of cond. If no successful
|
||
|
<tt> <test> </tt> expression is found, cond returns NIL. If a successful
|
||
|
<tt> <test> </tt> expression is found, but its clause contains no <tt> <body> </tt>
|
||
|
expressions, the result of the <tt> <test> </tt> expression is returned as
|
||
|
the result of cond.
|
||
|
<P>
|
||
|
<b> Examples:</b>
|
||
|
<P>
|
||
|
<BLOCKQUOTE>
|
||
|
<PRE>> (setq a '3)
|
||
|
3
|
||
|
> (setq b '4)
|
||
|
4
|
||
|
|
||
|
> (cond ((= a b) 'equal)
|
||
|
((< a b) 'b-is-bigger)
|
||
|
(t 'a-is-bigger))
|
||
|
B-IS-BIGGER
|
||
|
|
||
|
> (setq action 'square-both)
|
||
|
SQUARE-BOTH
|
||
|
|
||
|
> (cond ((equal action 'clear-both)
|
||
|
(setq a 0)
|
||
|
(setq b 0))
|
||
|
((equal action 'square-both)
|
||
|
(setq a (* a a))
|
||
|
(setq b (* b b)))
|
||
|
((equal action 'square-a)
|
||
|
(setq a (* a a)))
|
||
|
((equal action 'square-b)
|
||
|
(setq b (* b b))))
|
||
|
16
|
||
|
|
||
|
> (cond ((= a 5) 'found)
|
||
|
((= b 5) 'found))
|
||
|
NIL
|
||
|
|
||
|
> (cond ((+ a 1))) ; strange use of cond
|
||
|
10 ; before this, a was 9 due to previous
|
||
|
; cond clauses
|
||
|
</PRE>
|
||
|
</BLOCKQUOTE>
|
||
|
<P>
|
||
|
<BR> <HR>
|
||
|
<P>
|
||
|
<ADDRESS>
|
||
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
||
|
March 2007 </I>
|
||
|
</ADDRESS>
|
||
|
</BODY>
|