Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.
Representing expressions: Consider the following table:
Scheme expression | representation of Scheme expression |
---|---|
(* 3 10) |
(make-time 3 10) |
(+ (* 3 3) (* 4 4)) |
(make-plus (make-time 3 3) (make-time 4 4)) |
(+ (* x x) (* y y)) |
(make-plus (make-time 'x 'x) (make-time 'y 'y)) |
(* 1/2 (* 3 3)) |
(make-time 1/2 (make-time 3 3)) |
It suggests a representation of numbers, variables, additions, and products via structures.
numeric?
. The program consumes
(the representation of) a Scheme expression. It produces false, if
the expression contains a (representation of a) variable. Otherwise,
it produces true.
subst
. The program consumes (the
representation of) a variable (V), a number (N), and
(the representation of) a Scheme expression. It produces an
structurally equivalent expression in which all occurrences of
V are substituted by N.
value
. The program consumes
(the representation of) a Scheme expression. If the expression is
numeric (see above), it produces the number that DrScheme would
produce for the actual Scheme expression. Otherwise, it returns
false.
Note: If you wish to understand Scheme even better, invent a representation for Scheme function definitions of one argument:
(define (function variable) expression)Furthermore, extend the data definition for expressions so that you can represent function applications:
(function expression)
Now, modify the function value
so that it consumes an
expression and a list of (representations of) definitions. It still
computes the numeric value of numeric expressions, and returns false
if the expression is not numeric.
You must adjust the definition of numeric?
.
Hint: You will need a function to lookup the definition of a (representation of a) defintion. But you have seen this before.
You will not receive credit for any of the problems mentioned in this note. If, however, you choose to solve these problems, you will begin to understand why the design recipes and the templates lead to good code. Enjoy! End of note
Matthias Felleisen | This page was generated on Fri Mar 5 09:05:54 CST 1999. |