## CS 2420-20 Homework 13

Due: Thursday, March 3rd, 2011 9:10am

### Part 1 – Testing Numbers

Start with miniracket3.rkt (same password as before).

Add support for booleans as values and expressions, and also add an `iszero`
form that has a single sub-expression. If the value of the `iszero`
sub-expression is `0`, then the result should be true. If the value of the
sub-expression is any other number, then the result should be false.

For example, assuming that you name the new expression structure `iszero`,
`(evaluate (make-iszero (make-minus 7 7)) empty (hash))` should produce
`#t` — assuming that your representation of a boolean value is a Racket boolean — while
`(evaluate (make-iszero (make-plus 7 7)) empty (hash))` should produce
`#f`.

### Part 2 – Adding Conditionals

Add an `if` form to the language. You will need to name the
structure for `if` forms something other than `if`, perhaps
`branch`.

For example, assuming that you name the new expression structure `branch`
and that you represent Mini Racket booleans using Racket booleans, then
`(evaluate (make-branch (make-iszero 0) 1 0) empty (hash))` should produce `1`,
while `(evaluate (make-branch (make-iszero 6) 1 0) empty (hash))` should produce `0`.

As an extended example,

(evaluate (make-app 'fact 6)
empty
(hash 'fact
(make-function 'n
(make-branch (make-iszero 'n)
1
(make-times 'n (make-app 'fact
(make-minus 'n 1))))
empty)))

should produce `720`.

Last update: Thursday, April 7th, 2011mflatt@cs.utah.edu |