Re: Solutions To Assignment 3
Dear CSCI-316 Students,
Please do items 1 to 6 below after you have finished Lisp Assignment 4. As mentioned in the assignment document, you should try to finish Lisp Assignment 4 well before its due date. If possible, finish the assignment before we meet for our 14th class this coming Monday (27th) or within 24 hours of Monday’s class.
Items 1, 3, and 6 below are parts of Lisp Assignment 5, which is already available to you on Brightspace. Items 2, 4, and 5 are related reading assignments.
You should try to complete items 1 and 2 below before we meet for our 15th class this coming Wednesday (10/29).
Try to complete item 3 below before we meet for our 16th class on Monday of the week after next (i.e., 11/3), and try to do the reading assigned in items 4 and 5 by Wednesday of the week after next (i.e., 11/5). You will receive a reading assignment and homework exercises on a new topic no later than 11/7.
See you in class on Monday.
Item 1: Section 1 Problems
Do the 3 problems in Section 1 of Lisp Assignment 5. Try to do those problems before we meet for our 15th class this coming Wednesday (10/29).
Item 2: Reading Assignment
Read sections 8.3, 8.7, 8.11, 6.5.2, and 8.12 of Touretzky. (You are not required to do the Exercises.) As with item 1, try to do this reading before Wednesday’s class.
Item 3: Part I Problems
Do the 10 problems in Part I of Section 2 of Lisp Assignment 5. Note that solutions to problems 1-3 can be derived from solutions to problems A-C. You should aim to do these 10 problems before we meet for our 16th class on Monday of the week after next (i.e., 11/3).
Item 4: Higher-Order Functions Reading
Read secs. 7.1-7.6, 7.8, 7.11, 7.15, 8.16, 8.17, and 3.21 of Touretzky. (You are not required to do the Exercises.)
NOTE: In Common Lisp, a function argument that is a lambda expression may be written as (lambda ... ) or as #'(lambda ... ). Although Touretzky writes #'(lambda ... )—see, e.g., sec. 7.11—I will usually write (lambda ... ). You should aim to finish this reading no later than Wednesday of the week after next (i.e., 11/5).
Item 5: Anonymous Functions Reading
In the course reader, read the “Anonymous Function Values” subsection on pp. 389-90, the definitions in Fig. 10.5 on p. 397, and the “Mapping a Function…” subsection on pp. 399-400. However, Sethi uses Scheme instead of Common Lisp (so in Sethi’s code you will not see #' and funcall, and map is used instead of mapcar). As with item 4, try to do this reading no later than Wednesday of the week after next (i.e., 11/5).
Item 6: Part II Problems
Do the 6 problems in Part II of Section 2 of Lisp Assignment 5. The due date for this assignment is Tuesday, Nov. 11, but you will receive a reading assignment and homework exercises on a new topic well before that date, and you will need to do that reading and those exercises before Exam 1.
Hints for Items 3 and 6
Hint (i): Problems 8 and 9
For problem 8, I suggest that your UNREPEATED-ELTS function compute (UNREPEATED-ELTS L) from (UNREPEATED-ELTS (CDR L)) for some nonempty lists L, but compute (UNREPEATED-ELTS L) from (UNREPEATED-ELTS (CDDR L)) for other nonempty lists L. You can use an analogous approach to solve problem 9.
Hint (ii): Problem 11
The Scheme function remove-if defined in Fig. 10.5 of the course reader is very similar to the SUBSET function you are asked to write for problem 11! But, whereas (SUBSET p L) should return a list of all the elements of L that satisfy the predicate p, (remove-if p L) returns a list of all the elements of L that DO NOT satisfy p: SUBSET should behave like the REMOVE-IF-NOT function in sec. 7.8 of Touretzky.
Hint (iii): Problem 16(c)
The (map list ...) example on p. 400 of the course reader is relevant to problem 16(c)!
T. Yung Kong, D.Phil.
Professor
Computer Science Department
Queens College, CUNY
Flushing, NY 11367, USA