|First Lisp Assignment: Finger exercises
List containing zero or more
AToms (and only atoms), and
Do not do any error checking in your functions! Assume that the parameters to your functions are of the correct type. (Checking the types of parameters would add too much complexity to your program.)
(MY-REMBER A LAT)
LATwith all occurrences of the atom
Aremoved; remaining elements are in the same order as those in
LAT. Hint: use
CDRto tear the list apart, and
CONSto build the new list.
(MY-APPEND L1 L2)
L1, in their original order, followed by all the elements of
L2, in their original order. For example,
(APPEND '(A B C) '(X Y Z))should give
(A B C X Y Z).
(A B (C D))becomes the list
((C D) B A). Hint: you probably need
LAT. For example, given
(A B C A D A B),
(A B C D). (It is OK for your version of
MY-MAKESETto return the list in a different order, so long as the correct atoms are present.)
Lwith all sublists removed, leaving only the top-level atoms. For example, if
(P (Q R) ( ) (( )) S), the result should be
(P NIL S).
L, but retains all parentheses. If
(P (Q (R S)) T U (V) ( )), the result is
((( )) ( ) ( )), or in other words,
((NIL) NIL NIL). Note that in this problem
NILmust be treated as a list, not as an atom.
Lat all levels. For example, if
(A (B C (D)) E),
(E ((D) C B) A).
(MY-REMBERALL A L)
Lwith all occurrences of the atom
Aremoved. This differs from
Lmay be an arbitrary list, and the atoms
Amay occur at any level within
Lwith all inner parentheses removed. For example, given
(A (B C (D) ( ) E)),
(A B C D E). The order of atoms must be preserved.
These functions are roughly in order of increasing difficulty (
may be a little more difficult than some that follow it). Once you have written
a function, use it in other functions as appropriate--if you don't, some functions
will be very difficult!
Note: Some of these functions (such as
REVERSE) are already
defined in Lisp; I have added the prefix
MY- in order to avoid
name conflicts. Please do not use any of those Lisp functions in this assignment.
Note: Lisp always prints the empty list as
NIL rather than
( ), and there is no easy way to change this. So in some
of the above functions (especially
MY-SKELETON) you will have to
make the translation mentally.