next up previous
Contents Next: More Functions and Up: LISt Processing Previous: Selectors: First and

Changing Variable Values

What happens to the value of a, after saying (cons 'a a)? Nothing. That is, it looks like this:

>(cons 'a a)
(a a s d f)
>a
(a s d f)
Obviously, it would be useful to make these changes stick sometimes. To do that you can use setq as follows:

>(setq a (cons 'a a))
(a a s d f)
>a
(a a s d f)
and henceforth, that is the new value of a.

We'll let you play with the possibilities here, but using setq with just the three functions first, rest, and cons you can do anything 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.



© Colin Allen & Maneesh Dhagat
November 1999