70 lines
2 KiB
HTML
70 lines
2 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> cons (FUNCTION)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" cons (FUNCTION)">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node89.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="node87.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="node89.html"> defun (MACRO)</A>
|
|
<B>Up:</B>
|
|
<A HREF="node72.html"> Appendix: Selected Lisp </A>
|
|
<B> Previous:</B>
|
|
<A HREF="node87.html"> cond (MACRO)</A>
|
|
<BR> <HR> <P>
|
|
<H1> cons (FUNCTION)</H1>
|
|
<P>
|
|
<b> Format:</b>
|
|
<tt> (cons <exp1> <exp2> )</tt>
|
|
<P>
|
|
<b> Required arguments:</b>
|
|
2
|
|
<P>
|
|
<tt> <exp1> </tt>: any Lisp expression
|
|
<tt> <exp2> </tt>: any Lisp expression
|
|
<P>
|
|
Both argument expressions are evaluated. In common usage, the
|
|
second expression usually returns a list. In this case, cons creates
|
|
a new copy of the list returned by <tt> <expr2> </tt>, and makes the value
|
|
returned by <tt> <expr1> </tt> the new first element in this list. However, if
|
|
<tt> <expr2> </tt> returns an atom, cons returns the <em> dotted pair</em>
|
|
of the values of the two expressions.
|
|
<P>
|
|
<b> Examples:</b>
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (cons 'a '(1 2 3))
|
|
(A 1 2 3)
|
|
|
|
> (cons '(a) '(1 2 3))
|
|
((A) 1 2 3)
|
|
|
|
> (setq a 3)
|
|
3
|
|
> (cons a (list 'i 'j 'k))
|
|
(3 I J K)
|
|
|
|
> (cons 'a a)
|
|
(A . 3) ;;a dotted pair
|
|
|
|
> (cons '(1 2) 'q)
|
|
((1 2) . Q) ;;another dotted pair
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
<P>
|
|
<BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
March 2007 </I>
|
|
</ADDRESS>
|
|
</BODY>
|