CS 343: List Manipulation Practice        
Due: September 7, 2007, in class.
For each of the following Lisp expressions, write on paper the
answer that the Lisp interpreter would give if you typed in the expression.
When variable values are defined using setq,
use the new value of the variable in subsequent evaluations.
You can use the computer to check your answer after doing each
question yourself by hand. Try some variations on these examples.
- (setq colors '(red yellow ((orange) grey) ((blue) green)))
- (car colors)
- (first colors)     first is a synonym for car
- (cdr colors)
- (rest colors)     rest is a synonym for cdr
- (cadr colors)
- (second colors)
- (caddr colors)
- (third colors)
- (cdddr colors)
- (cdaddr colors)
- (car (caaddr colors))
- For each color in the structure colors, write Lisp
code to extract that color.
- (cons 'cat '())
- (cons '(cat mouse) '())
- (setq animals '(cat mouse))
- animals
- (cons 'bear animals)
- animals
- (setq animals (cons 'moose animals))
- animals
- (car animals)
- (cons '(bear lion) animals)
- (append animals '(tiger giraffe))
- animals
- (append animals animals animals)
- (setq birds (list 'jay 'grackle 'eagle))
- (cadr birds)
- (list birds animals)
- (append birds animals)
- (car (list '(armadillo) birds))
- (setq zoo (append animals birds))
- (cadr zoo)
- (car birds)
- (reverse animals)
- (car (last birds))
- (eql 'a 'a)
- (eql '() nil)
- (eql '(a) '(a))
- (equal '(a) '(a))
- (eql 2.0 2.0)
- (length zoo)
- (+ (length animals) (length birds))
- (= (+ (length animals) (length birds))
(length (append animals birds)))
- (member 'cat animals)
- (member 'dog animals)
- (assoc (car animals) '((bear 100) (moose 200) (walrus 300)))
Gordon S. Novak Jr.