CSE 341 -- Programming Languages
Spring 2003
|
Department of Computer Science and Engineering,
University of Washington
Steve Tanimoto (instructor)
|
Assignment
2
Version 1.00 of March 31 |
Lisp Warmup
Due date and time: Thursday, April 10,
2003 (at the beginning of section).
Turn in this assignment as a hardcopy printout. |
Title: Introduction to Lisp.
Purposes: Learn to use Lisp syntax,
built-in functions, how to define recursive functions,
understand Lisp evaluation, and how to manipulate list structures.
Instructions: Read pages 2-73
in Symbols, Programs, Interaction. (You may purchase
a copy at Professional Copy 'N' Print at 4200 University Way, N.E., at the corner
of N.E.42nd St. and the Ave. If they are out, order one for pickup the next day.) Do the following exercises:
- A. pp.10-12 # 1a-f; #2a-d;
- B. p.16 # 1b, d, e; #2a, b, f, g; #3a-h
- C. pp. 23-24 #1; #2.
- D. Write a recursive function
SUM-SQUARES
that takes a list of numbers and returns the sum of their squares.
For example, (SUM-SQUARES '(2 3 4)) should return 29.
Implement your function in Lisp and demonstrate it on
this example and another of your own choosing.
- E. In this exercise, we'll explore
"deep" processing of data.
Write a doubly recursive function DEEP-ROTATE that accepts a list
and returns the list with the original last element moved to the
beginning of the list. If there are any sublists in the list,
then those would be rotated as well. The same goes for any
sub-sublists, etc.
(DEEP-ROTATE '(DO THE ROTATE (RECURSIVELY PROCESSING) NOW))
;; should produce (NOW DO THE ROTATE (PROCESSING RECURSIVELY))
- F. Now let's work on processing
of more than one list at a time.
Write a recursive function INSERT-NUMBERS that will take two lists
as its arguments and process them as follows. The first list will
represent a template for a sentence, such as
(THERE WERE NUM CARS PILED UP ON ROUTE NUM).
The second list will contain a list of actual numbers
such as (13 520).
Your function will return a new list
in which each occurrence of the symbol NUM in the template has
been replaced by the next element of the list of actual numbers.
In this example, the result would be
(THERE WERE 13 CARS PILED UP ON ROUTE 520).
Any extra elements in the list of numbers are ignored.
Demonstrate your function on this example and a longer example of
your choice.
Scoring for this assignment: 5 points each for parts A, B, C, and D.
15 points each for parts E and F.
Total: 50 points.