60 lines
1.9 KiB
HTML
60 lines
1.9 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> Changing Variable Values</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Changing Variable Values">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node12.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
|
<A HREF="node2.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
|
<A HREF="node10.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="node12.html"> More Functions and </A>
|
|
<B>Up:</B>
|
|
<A HREF="node2.html"> LISt Processing</A>
|
|
<B> Previous:</B>
|
|
<A HREF="node10.html"> Selectors: First and </A>
|
|
<BR> <HR> <P>
|
|
<H1> Changing Variable Values</H1>
|
|
<P>
|
|
What happens to the value of a, after saying (cons 'a a)? Nothing.
|
|
That is, it looks like this:
|
|
<BLOCKQUOTE>
|
|
<PRE>> (cons 'a a)
|
|
(a a s d f)
|
|
> a
|
|
(a s d f)
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
Obviously, it would be useful to make these changes stick sometimes.
|
|
To do that you can use setq as follows:
|
|
<P>
|
|
<BLOCKQUOTE>
|
|
<PRE>> (setq a (cons 'a a))
|
|
(a a s d f)
|
|
> a
|
|
(a a s d f)
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
and henceforth, that is the new value of a.
|
|
<P>
|
|
We'll let you play with the possibilities here, but using setq with
|
|
just the three functions first, rest, and cons you can do <em> anything</em>
|
|
you want to with lists. These primitives are sufficient. Append and
|
|
list are strictly superfluous -- although they are very convenient.
|
|
For practice, try to achieve the same effects using just first, rest,
|
|
and cons as in the examples that used append and list, above.
|
|
<P>
|
|
<BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
March 2007 </I>
|
|
</ADDRESS>
|
|
</BODY>
|