CS217 Assignment 7, Due Monday, May 15, 2000

Submit assgn7.scm by hsp.
The file must contain at least your name and a comment before each problem, indicating its number and other info you feel is required.

  1. Starting with continuation-passing interpreter interp4-1cps.scm, implement and test while-do. Study implementations of varassign-exp and begin-exp to get the idea.

    Recall the grammar

    (expression
      ("while" expression "do" expression)
      while-do-exp)
    
    and code
    (while-do-exp (test exp)
      (eval-while-do test exp env))
    
    where
    (define eval-while-do
      (lambda (test exp env)
        (if (true-value? (eval-expression test env))
    	(begin
    	  (eval-expression exp env)
    	  (eval-while-do test exp env))
    	1)))
    
    Or see interp3-7loop.scm.

    This has to be translated to CPS and a while-do-cont continuation has to be constructed.

  2. Examine and experiment with Scheme.java, a call-by-value interpreter in Java that parses and evaluates list syntax. Compile with

    javac Scheme.java
    
    and run with
    java Scheme
    
    or
    java Scheme file.scm
    
  3. Complete and test definition of If class.
  4. Modify
    let index = proc (n, l)
                  letrec loop(l) = if null?(l) then raise sub1(0)
                                   else if equal?(n, car(l)) then 0
                                   else add1((loop cdr(l)))
                  in try (loop l) handle proc (x) x
    in begin
         print((index 1 list(2, 3, 4)));
         print((index 3 list(2, 3, 4)));
         (index 4 list(2, 3, 4))
       end
    
    to add parameters lo and hi to index, so
    (index n lst lo hi) => index of n in lst if n occurs in pos n to m
                           else -1
    
    Have your expression print the results of several calls, which test index in all cases. Use interp4-4exc.scm

assgn7.scm must be loadable into Scheme and procedures must pass tests of correctness.