First Lisp Assignment: Finger exercises
CIT594, Spring 2003, Dave Matuszek

Write and test the following Lisp functions. Assume:

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.)

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 CAR and CDR 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 MY-APPEND and LIST.

Removes duplicate atoms occurring in LAT. For example, given (A B C A D A B), MY-MAKESET returns (A B C D). (It is OK for your version of MY-MAKESET to return the list in a different order, so long as the correct atoms are present.)

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), MY-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 MY-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)), MY-COLLAPSE returns (A B C D E). The order of atoms must be preserved.

These functions are roughly in order of increasing difficulty (MY-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!


Due date, Blackboard, and grading:

Blackboard has not yet been set up for this class. Assuming that it is set up by next week, the assignment will be due on Thursday, January 23, before midnight. I have not yet decided on a late policy.

There are ten functions, and each is worth 10%. Each function will receive full credit or no credit; faulty functions will not receive partial credit. The examples given above are to illustrate what the function should do;