perm filename HOMEW0.F79[206,LSP]1 blob
sn#476804 filedate 1979-09-26 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 .REQUIRE "LSPMAC.PUB[LSP,CLT]" source_file
C00003 00003 .hd206 FALL 1979
C00008 ENDMK
C⊗;
.REQUIRE "LSPMAC.PUB[LSP,CLT]" source_file;
.PAGE FRAME 56 HIGH 80 WIDE;
.evenleftborder ← oddleftborder ← 1000;
.area text lines 1 to 56;
.place text;
.
.MACRO hd206 (TERM) ⊂
.BEGIN NOFILL TURNON "←→"
←COMPUTER SCIENCE DEPARTMENT
←STANFORD UNIVERSITY
.SKIP
CS206 ←RECURSIVE PROGRAMMING AND PROVING →TERM
.TURNOFF
.END ⊃
.
.
.MACRO hw (NUMBER, DUEDATE) ⊂
. BEGIN TURNON "←" NOFILL
←PROBLEM SET NUMBER
←Due DUEDATE
. TURNOFF END ⊃
.
.itemmac
.
.lspfont
.basicops
.allops
.
.PORTION MAINPORTION
.
.hd206 FALL 1979
.skip
.hw 0, |Oct. 5|
Below are some expressions, given first in internal, then
in external notation. You should evaluate these expressions, by
hand, according to the rules presented in Chapter I. When you are done
go to LOTS and type the expressions (in internal form)
to LISP and check the value returned against your answer.
If there is something you don't understand try "stepping" through the evaluation.
(See the MACLISP manual, or LISP at LOTS.)
These exercises are to get you going and not to be handed in.
Some of the expressions involve user defined programs. The definitions
are given in Chapter I. To save you some typing, the necessary definitions
have been collected in a file which may be read in by typing:
⊗⊗⊗$$(DSKIN (DSK |C.CS206|) HW0 F79).$⊗
.begin nofill
.group
$$(QUOTE (A B C))$
$$(A B C)$
.apart
.group
$$(QUOTE (A . (B . C)))$ ;;;Note how LISP prints the value.
$$(A B . C)$
.apart
.group
$$(CADAR '((X (Y Z)) B C))$
⊗⊗qada $$((X (Y Z)) B C)$⊗
.apart
.group
$$(FRINGE '(A . B))$ ;;;⊗fringe is defined on page 17.
⊗⊗fringe $$(A . B)$⊗
$$(FRINGE '(A B))$
⊗⊗fringe $$(A B)$⊗
.apart
.group
$$(ASSOC 'X '((Y . 1) (X . 5) (A . (1 2 3))))$
⊗⊗assoc[$$X$, $$((Y . 1) (X . 5) (A 1 2 3))$]⊗
;;;⊗assoc is defined on page 21
.apart
.group
$$(SUBST (CONS 1 NIL) '?X (CONS (CONS (CONS 'A 'B)'?X) NIL))$
⊗⊗subst[1 . qNIL, $$?X$, [[$$A$ . $$B$] . $$?X$] . qNIL]⊗
;;;⊗subst is defined on page 16
.apart
.group
$$((LAMBDA (L) (LIST 'COND (LIST (CADR L) (CADDR L)) (LIST T (CADDDR L))))$
$$__'(IF (NULL NIL) NIL (CDR NIL)))$
⊗⊗[[λl: <$$COND$, <qad l, qadd l>, <qT, qaddd l>>]⊗
⊗⊗_[$$(IF (NULL qNIL) qNIL (CDR qNIL))$]]⊗
.apart
.group
$$(EVAL ((LAMBDA (L)$
$$_________(LIST 'COND (LIST (CADR L) (CADDR L)) (LIST T (CADDDR L))))$
$$______'(IF (NULL NIL) NIL (CDR NIL)) ))$
⊗⊗eval [[λl: <$$COND$, <qad l, qadd l>, <qT, qaddd l>>]⊗
⊗⊗______[$$(IF (NULL qNIL) qNIL (CDR qNIL))$]]⊗
.apart
.group
$$(EXTENSIONS '(B A) $
$$____________'((A B) (B A C D) (C B D E) (D B C E) (E C D F) (F E)))$
⊗⊗extensions[$$(B A)$,⊗
⊗⊗$$_________'((A B) (B A C D) (C B D E) (D B C E) (E C D F) (F E)))$]⊗
where ⊗extensions is a program to compute all extensions of length 1 of
given path in a given graph. (see page 2 for representation of graphs)
$$(DEFUN EXTENSIONS (PATH GRAPH)$
$$____(MAPCAR (FUNCTION (LAMBDA (X) (CONS X PATH)))$
$$__________(CDR (ASSOC (CAR PATH) GRAPH))))$
;;;⊗mapcar is defined on page 23
.apart
.group
$$(DIFF '(TIMES X (PLUS Y 3) 1) 'X)$ ;;;⊗diff is defined on page 24
⊗⊗diff[$$(TIMES X (PLUS Y 3) 1)$, $$X$]⊗
.apart
.end
The following expressions all contain some sort of error. See if you
can find the error. The type the expression to LISP so see what
sort of error message you get. (Remember to type <control>G to
get out to the "break-loop" after an error occurs.)
.begin verbatim select 6 group
(ATOM A)
(CADR '((FOO.BAZ).GLUB))
(CONS '(A B) (CONS 'C))
(CONS ('(A B) 'C))
(COND (ATOM '(A.B) T) (T (CDR '(A.B))))
.end