Lisp
Self Test #1
CIS347
First
section: Winston & Horn
Be
prepared to do any of the exercises in Winston & Horn, Chapters 2- 4,
either in their original form or in slightly altered form. Answers to those exercises
have been posted
under the “Study Material” link.
For the remaining sections, try to answer all of the questions first.
Second
section: application
What will Lisp return when
the following forms are typed at the top level. Assume no global variables have been initialized, except as
specifically indicated.
1. (cons 'e '(a b c))
2. (cons '(a b) '(a b))
3. (append '(a b) '(a b))
4. (append 'a '(a b))
5. (list 'a 'b 'c)
6. (list '(a) 'b 'c)
7. (list 'a '(b 'c))
8. (list 'a '(b 'c))
9. (first '(a b c))
10. (first '((a b)(c d))
11. (first '(((((a) b) c) d) e))
12. (rest '(a b c))
13. (rest '((a b)(c d))
14. (rest '(((((a) b) c) d) e))
15. (nth 3 ‘(1 2 3 4 5 6))
16. (nth 3 ‘(0 1 2 3 4 5 6))
17. (third 3 ‘(1 2 3 4 5 6))
18. (third 3 ‘(0 1 2 3 4 5 6))
19. (null '())
20. (null '(a))
21. (null 'a)
22. (null nil)
23. (endp '())
24. (endp '(a))
25. (endp 'a)
26. (endp nil)
27. (zerop 0)
28. (zerop 1)
29. (zerop ‘a)
30. (if 1 2 3)
31. (if nil 2 3)
32. (if nil 2)
33. (if 1 2)
34. (if 1)
35. (if (= 2 3) (+ 2 3) (* 5 7))
36. (cond
(1 2)
(3 4))
37. (cond
(nil 1)
(nil 2)
(t 3))
37. (cond
(1 2 3 4)
(5 6))
38. (cond
((> 3 2)(+ 5 6)(* 2 5)(/ 6 2))
(5 6))
39. (or 1 2 3)
40. (or nil 2 3)
41. (or 1 nil 3)
42. (and 1 2 3)
43. (and 1 nil 3)
44. (eq 'a 'a)
45. (eq '(a) '(a))
46. (equal 'a 'a)
47. (equal '(a) '(a))
Assume the values of x, y
and z have been set, as below:
(setf
x '(a b))
(setf
y x)
(setf
z '(a b))
48. (eq x y)
49. (eq x z)
50. (equal x y)
51. (equal x z)
Third
section: theory
Use the Word Bank below for all questions except #30.
1. The basic execution unit in
Lisp is the _____.
2. Sometimes forms are called
_____.
3. The basic component of Lisp
programs is the _____.
4. For our purposes, _____
function in Lisp returns some value.
5. If a function also carries
out an action, this action is called a _____.
6. Lisp programs are _____.
7. Lisp is a _____ language,
though not a pure one.
8-9. The basic data units in Lisp
programs is the _____ and the _____.
10. Atoms are _____ units.
11. T/F: Whereas an atom can be the
name of a variable, it cannot also be the value of a variable.
12. Lists are _____ sequences of
elements.
13. T/F: The elements of a list can
be atoms, but they cannot be lists.
14. Syntactically, the definition
of a user-defined function is a _____.
15. T/F: Lists are also Lisp forms.
16. In Lisp, t and nil
evaluate to
_____.
17. The Lisp interpreter
considers any _____ value to be true.
18-19. In addition to functions,
Lisp has _____ and _____.
20. In Lisp, numbers evaluate to
_____.
21. When a list is to be
evaluated, the Lisp interpreter expects the first element of the list to be
_____.
22-23. Except in special
circumstances, the remaining elements of the list are taken to be _____ and are
_____.
24-26. Meaningful Lisp forms may be
divided into three categories. These
are:
27-29. When viewed as forms to be
evaluated, lists may be divided into three categories. These are:
30. Lisp runs in a
a.
Fetch-Execute cycle c. Read-Eval-Print loop e. none of these
b.
Recognize-Act cycle d. All of these
(31-33) Identify these Lisp
functions and/or special forms.
31. Constructs a new list by
placing all of its arguments as elements of the new list.
32. Constructs a new list by
placing <element> at the head of <list>, returning a pointer to
that new list.
31. Constructs a new list by placing the elements of <list1>
in front of the
elements
of <list2>.
Lisp
Self Test #1
Word
Bank for Third Section (theory)
CIS347
A. append AA. non-null
B. arguments BB. null
C. assembly CC. ordered
D. atom DD. self-evaluating forms
E. collections
of functions EE. s-expressions
F. False FF. side effect
G. cons GG. some
H. evaluated HH. special forms
I. every II. symbols
J. form JJ. themselves
K. function KK. unordered
L. functional
M. function
calls
N. indescribable
O. indivisible
P. irreplacable
Q. list
R. lists
S. machine
T. True
U. macro
calls
V. macros
W. the
name of a function
X. nil
Y. no
Z. non-nil
After completing this Self
Test, you can check
your answers
here.