Computer Science Name
-
LISP worksheet #3
Do the following exercises. Evaluate the final expression. Be sure to enclose answers that are lists in parentheses and to write answers that are individual atoms without parentheses.
1.
(SETQ x '(r o y g b p))
(CAR (CDR (REVERSE (CDR (CDR x)))))
2.
(ADD 1 (MULT 2 3) (SUB 4 5))
3.
(SETQ x '((a b) c d (e f)))
(CAR (CDR (REVERSE (CDR x))))
4.
(SETQ a (MULT 2 3))
(MULT (ADD 3 4) a)
5.
(SUB (SUB 9 3) (SUB 100 98))
6.
(MULT (DIV 12 4) (ADD 8 0))
7.
(SETQ x (CDR (CDR '(a b c d))))
(CAR (CDR (REVERSE x)))
8.
(SETQ w (ADD 3 (MULT 2 6)))
(SUB ((ADD w 1) w)
9.
(DEF funny(a) (CAR (CDR (REVERSE a))))
(SETQ a '(1 2 3 4 5 6 7))
(SETQ b '(9 8 7 6 5))
(ADD (funny a) (funny b))