## CS 2420-20 Homework 13

Due: Tuesday, March 6th, 2012 9:10am

### Part 1 – Testing Numbers

Start with miniracket2.rkt (password required; check your e-mail).

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)) (hash))` should produce
`#t` — assuming that your representation of a boolean value is a Racket boolean — while
`(evaluate (make-iszero (make-plus 7 7)) (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) (hash))` should produce `1`,
while `(evaluate (make-branch (make-iszero 6) 1 0) (hash))` should produce `0`.

As an extended example,

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

should produce `720`.

Last update: Wednesday, March 7th, 2012mflatt@cs.utah.edu |