LISP Homework Solutions
This web page provides answers to most of the questions asked in the
LISP Homework assignment. (Some of the
box and pointer diagrams are missing.)
I apologize for the messy page layout; this is what you get when you save a complex Word document as a web page.
Answers: A
is a symbol, and the interpreter will return its value binding unless it
doesn’t have one, in which case the interpreter will signal an error. 'A is a quoted symbol, and the interpreter
will return A, the symbol’s print name.
#\A is the character A, and the interpreter will return that character.
Answers: A, (X Y Z)
(RED 1)
((SIZE-OF-HALL 250))
(OIL VINEGAR)
(#\b)
((“marsh” 43))
(RENT (+ (* 1/3 ACTUAL-RENT) PARKING-SPACE))
6
Answers: (car (cdr (cdr '(table lamp chair shelf))))
(car (car (cdr '((table lamp) (chair computer)))))
(car (car (car (cdr (cdr '(computer (shelf) ((chair)) (((sofa)))))))))
(car (cdr (car '((((table) file‑cabinet) chair) telephone))))
You should read Chapter 15 of the Wilensky book
before answering the next questions. Note that (cons 'a 'b)
is the
same as '(a . b)
.
For example, the dotted-pair representation of (a b s) is
(a . (b . (s . nil))). The spaces are required
around the dots when you type this, by the way. The difference between a dotted
pair and a list is that the cdr of each cons cell in a list is a pointer to
another cons cell, except the cdr of the last cons cell, which is NIL. But a
dotted pair is a cons cell with a cdr that points to something other than
another cons cell (or NIL).
Answers:
(apples . (bananas . (strawberries . nil)))
(value . ((first‑value . (second‑value . nil)) . nil))
((my‑symbol . (“my‑string” . nil)) (#\C . nil))
The (steve . harold) pair is a cons cell that does not look like a list, but the other cons cell looks like the first part of a list.
((PEANUT . BUTTER) BUTTER JELLY . BREAD) The third dot looks like a list with BUTTER as its CAR. Note that this list has two pointers to the same symbol, BUTTER.
This diagram is the same for both of the two forms above.