EECS 321 Programming Languages: Homework 4

Due: Friday, February 1st, 2013, noon

Part 1 – Functions that accept multiple arguments (with deferred substitutions)

Just like part 1 of homework 3, add multiple argument functions, but this time add them to the interpreter with deferred substitutions.

Part 2 – Conditionals

Add if0, a 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)```

Part 3 – Negative predicate

Implement, in the FnWAE language (without any extensions), 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).

Part 4 – Multiplication on integers

Implement, in the FnWAE language (without any extensions), a function mult that computes the product of two integers.

`  {deffun {mult x y} ...}`

Part N – Handin instructions

The final program you handin should:

• have definitions of parse and parse-defn that accept quoted versions of FnWAE and FunDef respectively (as above) and return the corresponding trees.
• have a definition of interp-expr with the contract FnWAE (listof FunDef) -> Number (it will be called with the result of your parsers) that supports both if0 and multi-arity functions.
• have a PLAI-level definition of mult-and-neg-deffuns that is bound to a list of (unparsed) deffuns that contains both neg? and mult as well as any helper functions you wish.
```(define mult-and-neg-deffuns
(list `{deffun {neg? x} ...}
`{deffun {mult x y} ...}
;; other deffuns okay, too
))```
• not have any unused code (i.e., no subst).
• have the 8 rules from the Provost's website (see the homework 1 assignment for more details).

 Last update: Friday, January 25th, 2013robby@eecs.northwestern.edu