Due: Wednesday, January 27th, 2010, 5pm
Just like part 1 of homework 3, add multiple argument functions, but this time add them to the interpreter with deferred substitutions.
Do not add rec or get.
Add if0, conditional expression. It has three subexpressions:
<FnWAE> = ... | {if0 FnWAE FnWAE FnWAE}
Evaluating an if0 expression evaluates the first subexpression; if it produces 0, then the result of the entire expression is the result of the second subexpression. otherwise, the result is the result of the third subexpression.
Examples:
(test (interp-expr (parse '{if0 0 1 2}) '()) 1) (test (interp-expr (parse '{if0 1 2 3}) '()) 3)
Implement, in the FnWAE language, a predicate neg? that determines if an integer is negative.
{deffun {neg? x} ...}
It must return either 0 (if the input is negative), or 1 (if not).
Implement, in the FnWAE language, a function mult that computes the product of two integers.
{deffun {mult x y} ...}
The final program you handin should:
(define mult-and-neg-deffuns (list `{deffun {neg? x} ...} `{deffun {mult x y} ...} ;; other deffuns okay, too ))
Last update: Monday, January 25th, 2010robby@eecs.northwestern.edu |