First Lisp Assignment
Dave Matuszek

Write and test the following Lisp functions. Please turn in a listing of your functions, along with a listing showing your tests of these functions.



returns as value the last S-expression which occurs as a member of the nonempty list NEL.


returns as value the list LAT with all occurrences of the atom A removed; remaining elements are in the same order as those in LAT. Hint: use FIRST and REST to tear the list apart, and CONS to build the new list.


forms one list composed of all the elements of 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).


reverses the elements of list L. For example, the list (A B (C D)) becomes the list ((C D) B A). Hint: you probably need APPEND and LIST.


removes duplicate atoms occurring in LAT. For example, given (A B C A D A B), MAKESET returns (A B C D).


returns as value the list L with all sublists removed, leaving only the top-level atoms. For example, if L is (P (Q R) ( ) (( )) S), the result should be (P NIL S).


removes all the non-nil atoms of list L, but retains all parentheses. If L is (P (Q (R S)) T U (V) ( )), the result is ((( )) ( ) ( )), or in other words, ((NIL) NIL NIL). Note that in this problem NIL must be treated as a list, not as an atom.


reverses the elements of L at all levels. For example, if L is (A (B C (D)) E), REVERSEALL should return (E ((D) C B) A).


returns as value the list L with all occurrences of the atom A removed. This differs from REMBER in that L may be an arbitrary list, and the atoms A may occur at any level within L.


returns the list L with all inner parentheses removed. For example, given (A (B C (D) ( ) E)), COLLAPSE returns (A B C D E). The order of atoms must be preserved.

These functions are roughly in order of increasing difficulty (REVERSE 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 are already defined in Common Lisp, but your definitions will take precedence over the system-defined functions.

Note: Lisp always prints the empty list as NIL rather than as ( ), and there is no easy way to change this. So in some of the above functions (especially SKELETON) you will have to make the translation mentally.