Read the Lisp Primer up to the Recursion and Iteration Section (included).
and answer and submitt following questions which are part of
the primer
excercises.
1.(5) Using first, rest and reverse extract the atom ``jim'' from the
following:
a. (he is dead jim)
b. (captain (((jim) kirk)))
c. (((((spock) asked) jim) if) he was
all right)
d. (after (looking at the (lizard man)
((((jim))) asked for warp 9)))
2.(5) Given the following definition:
(setf
mylist '((bush broccoli) (nixon watergate)
(letterman (viewer mail))
(you are no jack kennedy)
(and please) (scorsese (robert deniro))))
Construct the following with any of the
functions you have learned
so far.
a. (no broccoli please)
b. ((scorsese and deniro) are no robert
kennedy)
c. (watergate and no viewer)
d. (bush nixon kennedy)
e. ((bush broccoli) (nixon watergate)
(letterman mail))
3. (5) Consider the following definition:
(defun
life (a b)
(cond ((null a) b)
((null b) a)
(t 'its-tough)))
Suppose you are running the LISP interpreter
and you enter the
following:
>(setf a 'oh-boy)
Then you do the following:
>(life 'gummi a)
What are the global and local values
of a and b before, during,
and after this command?
4. (5) Consider the following function definition:
(defun
who-knows (lst1 lst2)
(cond ((= (length lst1) (length lst2))
(+ (length lst1) (length lst2)))
((> (length lst1) (length lst2)) (length lst2))
(t (length lst1))))
a. What does this function do?
Be precise as what would happen in each
case.
b. What happens if one of the
arguments is an atom ?
5.(5) Consider the following definition for the function CIRCULATE:
(defun
circulate (lst)
(append (rest lst)
(list (first lst))))
This function takes a list and constructs a new list by
taking the first
element of the old list and making it the last element
of the new.
For example:
>(circulate
'((whats) happening here))
(happening here (whats))
Rewrite the function and call it CIRCULATE-DIR so that
it can circulate
lists in both directions. Thus it should work as follows:
>(circulate-dir
'(1 2 3 4) 'left)
(4 1 2 3)
>(circulate-dir
'(1 2 3 4) 'right)
(2 3 4 1)
Instructions for submission:
----------------------------
(1) Using script or dribble, you are to capture the output of a Lisp
session
in which you successfully load and execute your
code, showing sufficient
testing of your function(s). On osf1 type script
and your session
will be saved in a file typescript, whose hardcopy
you will hand in.
To exit script simply type 'exit'.
(2) a. In class hand in a hardcopy report consisting of:
- a cover sheet containing:
Your name
CS580 Spring 2001,
J. Kosecka
Homework #1
(A short summary stating
whether you were successful, describing
any problems,
etc.)
- a print out of the Lisp code.
- a printout of a captured Lisp
session involving the execution of
the HW1 Lisp code.
b. Send a SINGLE email to clevcovi@cs.gmu.edu formatted
in the
following way:
- the subject field of the email should read: CS580 HW#1 Kosecka
- the content of the email should
be a commented version of the
Lisp code for HW1.
Comments at the top should include:
Your name
CS580 Spring 2001,
J. Kosecka
Homework #1
As a safety precaution, always
CC yourself when you submit homework
this way and keep it around until
it has been graded and returned.