1 Guidelines
1.1 Contracts & Test Cases
1.2 Handling errors
1.3 Language Level & File Format
2 Pair Programming
3 The Assignment
3.1 Laziness
4 Support Code
5 Acknowledgments
Version: 4.0.0.1

Assignment 4, CSC430, Spring 2008

1 Guidelines

1.1 Contracts & Test Cases

For this and all remaining assignments, every function you develop must come with the following things:

1.2 Handling errors

Your parser and interpreter must detect errors and explicitly signal them by calling (error ...). We will consider an error raised internally by Scheme to be a bug in your code.

For example, Scheme signals a "divide by zero" error if you attempt to evaluate (/ 1 0). Since we use Scheme’s division function to implement division in CFWAE, you may be tempted to leave it to Scheme to signal division by zero errors for you. However, you must signal the error yourself by explicitly testing for division by zero before calling Scheme’s division procedure.

Note that you may assume that your contracts are respected. That is, if your interp function’s contract indicates that it expects a CFWAE, you do not need to worry about miscreants that call it with a number or a string or another surprising value.

1.3 Language Level & File Format

NOTE: For this assignment, you must develop your solutions using the Programming Languages: Application and Interpretation: Pretty Big PLAI Scheme language level. (This is a change from last time.) Your test cases must use the (test ...) or (test/exn ...) form.

Your solution should take the form of a single file. Solve each problem separately, ands make sure that each solution appears in a separate part of the file, with comments separating each problem’s solution.

Hand in your solution using the handin server. For help with the handin server, please see the course web page.

2 Pair Programming

This assignment is a pair programming assignment. This means that you may work with at most one other person. You are not required to do so, but I strongly encourage it; if you don’t feel that you need the help, then work with someone who does.

To declare partners, both you and your partner must send me e-mail indicating this fact, at least three days before the assignment is due. In order to submit a pair programming assignment, use the string formed by joining your individual ids with a "+" in between. So, if my login is "clements" and my partner’s is "wilson", then we would submit as "clements+wilson". Don’t submit by yourself if you’re planning to work with a partner; an individual submission will prevent a later pair submission.

3 The Assignment

This assignment requires you to make two changes to your solution for Program 3. First, you must remove the "with" expression from the abstract syntax definition, as we did in class. Note that you must still support programs that use the "with" form; it’s just that your parser will now parse these into applications. Secondly, your interpreter must evaluate programs lazily.

3.1 Laziness

As we discussed in class, laziness does not change the meaning of programs–very much. In particular, things that evaluated to numbers in the eager interpreter will still evaluate to the same number, things that evaluated to functions should still evaluate to functions that "mean" the same thing, though they may appear a bit different. However, the lazy evaluator may produce answers for programs on which the eager evaluator ran forever or produced errors.

4 Support Code

Your code must adhere to the following template, without any changes:

  ; represents an expression

  (define-type CFAE

    [num (n number?)]

    [bool (b boolean?)]

    [binop (op procedure?) (lhs CFAE?) (rhs CFAE?)]

    [id (name symbol?)]

    [ifexp (tst CFAE?) (then CFAE?) (els CFAE?)]

    [fun (params (listof symbol?)) (body CFAE?)]

    [app (f CFAE?) (args (listof CFAE?))])

  

  ; represents an environment during evaluation

  (define-type Env

    [mtEnv]

    [anEnv (name symbol?) (value CFAE/L-Value?) (env Env?)])

  

  ; represents a possible result of evaluation

  (define-type CFAE/L-Value

    [numV (n number?)]

    [boolV (b boolean?)]

    [closureV (params (listof symbol?))

              (body CFAE?)

              (env Env?)]

    [exprV (expr CFAE?)

           (env Env?)

           (cached box?)])

  

  

  ; parse : expression -> CFAE

  ; This procedure parses an expression into a CFAE

  (define (parse sexp)

    ...)

  

  ; interp : CFAE -> CFAE/L-Value

  ; This procedure interprets the given CFAE and produces a result

  ; in the form of a CFAE/L-Value (either a boolV, a closureV, a numV,

  ; or an exprV)

  (define (interp expr)

    ...)

  

  ; interp-with-env : CFAE Env -> CFAE/L-Value

  ; This procedure interprets the given CFAE in the given environment

  (define (interp-with-env expr env)

    ...)

5 Acknowledgments

Thanks to Shriram Krishnamurthi and Greg Cooper for these assignments.