CS 307: 5. List Manipulation
Due: Wednesday, October 3, 2001
No certification sheet is required for this assignment. Write your
TA's name and discussion section time on your paper.
Run at least two of the exam1 lessons of the Scheme Tutor.
Hand in a copy of your Scheme Tutor runs for grading.
Download the Tutor again, since some lessons have been added.
Of course, it will be to your advantage to do more than two lessons;
these lessons are questions from previous exams.
List Manipulation Practice
Evaluate the following Scheme expressions. For each expression, give the
answer that the Scheme interpreter would give if you typed in the expression.
When variable values are defined using define or set!,
use the new value of the variable in subsequent evaluations.
Hand in handwritten answers for the following questions.
You can use the computer to check your answers after doing the
quesions yourself by hand. Try some variations on these examples.
- (define colors '(red yellow ((orange) grey) ((blue) green)))
- (car colors)
- (cdr colors)
- (cadr colors)
- (caddr colors)
- (cdddr colors)
- (cdaddr colors)
- (car (caaddr colors))
- For each color in the structure colors, write the Lisp
code to extract that color from the list structure.
- (cons 'cat '())
- (cons '(cat mouse) '())
- (define animals '(cat mouse))
- (cons 'bear animals)
- (set! animals (cons 'moose animals))
- (car animals)
- (cons '(bear lion) animals)
- (append animals '(tiger giraffe))
- (append animals animals animals)
- (define birds (list 'jay 'grackle 'eagle))
- (caddr birds)
- (list birds animals)
- (append birds animals)
- (list '(armadillo) birds)
- (car (list '(armadillo) birds))
- (define zoo (append animals birds))
- (cadr zoo)
- (car birds)
- (reverse animals)
- (car (reverse birds))
- (eqv? 'a 'a)
- (eqv? '() '())
- (eqv? '(a) '(a))
- (equal? '(a) '(a))
- (eqv? 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)))