CSCI 5535: Homework 5

Due date: November 10th at 5:00 p.m.
Please submit your solution on paper.

1. (20 points) Consider the following code fragment:
      PROCEDURE f()
          TRY
             g();
           EXCEPT
              E1 =>  <S1>
            END

      PROCEDURE h()
          TRY
             g();
           EXCEPT
              E2 =>  <S2>
            END

    PROCEDURE g()
        IF cond1 THEN
           RAISE E1;
        ELSE IF cond2 THEN
           RAISE E2;
        ELSE
           <S4>

    PROCEDURE Main()
        TRY
           f();
           h();
         EXCEPT
            ELSE => <S3>
          END

In the above code, don't worry about checked versus unchecked exceptions.  (a) Show the exception tables for the above code.  (b) Consider the following call sequence: Main->h->g and g raises exception E1.  Using the exception table, show how this exception is handled.

2.  (20 points) In class I presented a scheme for implementing exception handling for Java and Modula-3 (it's the same scheme you used in question 1 above).  Can this scheme be used if exceptions handlers have a dynamic scope as in PL/1.  Explain and give a supporting example.

3. (20 points) Closures are difficult to implement efficiently when nested functions can escape.  Consider a language that supports nested functions but wants to keep their implementation efficient by prohibiting nested functions from escaping.  Describe the compile-time and/or run-time checks that are necessary in order to prohibit nested functions from escaping.  For each check you describe indicate clearly if it is a compile time or a run-time check.

4.  (20 points) Write the following function:
       compare: ''a list * ''a list  -> bool
     "compare" takes a pair of lists, and returns true if the lists are identical and false otherwise.  Use continuations (callcc) in your code so that compare exits immediately if finds that the lists are not identical.