CSE 341 -- Programming Languages
Autumn 2001
|
Department of Computer Science and Engineering,
University of Washington
Steve Tanimoto (instructor)
|
Assignment
1
Version 1.01 of October 1 |
Introduction to Lisp
Due date and time: Wednessday, October 10,
2001 (at the beginning of class).
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:
- pp.10-12 # 1b, d, f; #2a-d;
- p.16 # 1a, d, e; #2a, d, e, f; #3a-f
- pp. 23-24 #3.
- p.31: # 2;
- Without using Common Lisp's
built-in function REVERSE, write a recursive function
MY-REVERSE that takes a list and returns a new list
in which the top-level elements are in reverse order.
Demonstrate your function on the list (A B C D) as well as a list
of your own choosing.
- In this exercise, we'll explore
"deep" processing of data.
Again without using Common Lisp's
built-in function REVERSE, write a recursive function
DEEP-REVERSE that takes a list and returns a new list
in which not only the top-level elements are in reverse order,
but any sublists have been reversed as well. Any sub-sublists should
be reversed, too, etc.
Demonstrate your DEEP-REVERSE function on two examples, one of which
is the list below and the other of which you make up yourself. Your
example should contain at least one sublist with at least three elements.
(THIS ILLUSTRATES (1 2 (3 4 5) 6 7) OK)
- Now let's work on processing
of more than one list at a time.
Write a recursive function PUT-IN-NOUNS 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 (A NOUN WENT TO THE NOUN).
The second list will contain a list of actual nouns such as
(ROCKET MOON SUN SPACECRAFT). Your function will return a new list
in which each occurrence of the symbol NOUN in the template has
been replaced by the next element of the list of actual nouns.
In this example, the result would be (A ROCKET WENT TO THE MOON).
Any extra elements in the list of nouns are ignored.
Demonstrate your function on this example and a longer example of
your choice.
-
Extend your solution to the previous exercise with one of
two options. Option A is to implement PUT-IN-NOUNS-AND-ADJS
which should take three lists instead of two. The third list
should be a list of adjectives like (LARGE SILLY GREEN).
The template can have ADJ elements to be replaced as well as NOUN
elements. So the call (PUT-IN-NOUNS-AND-ADJS '(A ADJ NOUN WENT TO
THE ADJ ADJ NOUN) '(ROCKET MOON SUN SPACECRAFT) '(LARGE SILLY GREEN))
should return the list (A LARGE ROCKET WENT TO THE SILLY GREEN MOON).
Option B is to introduce random selection of nouns, so that each
time a noun is selected to replace a NOUN element, it is chosen
at random from the list of nouns. You may implement either
random selection with replacement (a noun is not "used up" by
being selected) or without replacement (a noun should not be
reused).
Individual Work: This assignment
requires individual work. Do NOT work in teams on this assignment..