Programming Languages (CS 329) Homework 3 Computer Science and Engineering Out: 2000-10-16 Indian Institute of Technology Bombay Due: 2000-10-31

1. Use the standard semantics for FLK! described in class to interpret the following code:

    (let r = (new 1)
        (begin
            (r := (+ 1 (read r)))
            (read r)  )  )

In particular, use this example to explain why the standard semantics behaves as expected in spite of making to explicit mention of the store in the rules for begin, lambda, and call, although executing begin and call may change hte store.

(This is a slightly tedious exercise, but will help you a lot in understanding how the store is manipulated in standard semantics.)

2. In class we gave a translation from the callcc construct to FLCPS. Using this translation for guidance, give standard semantics for the callcc construct.

3. This question explores name lookups for exception handlers.

(a) What will the following Java code print when executed?

     class Main {
         static public void main(String [] args) {
             try {
                 try {
                     try {
                         throw new B_Exception("hello");
                     }
                     catch ( A_Exception a2ex ) {
                         System.err.println("inner " +
                             a2ex.getMessage());
                     }
                 }
                 catch ( B_Exception bex ) {
                     throw new A_Exception("world");
                 }
             }
             catch ( A_Exception a1ex ) {
                 System.err.println("outer " +
                                    a1ex.getMessage());
             }
         }
     }

                                                           class A_Exception
                                                               extends Exception { }

                                                           class B_Exception
                                                               extends Exception { }

(b) Is the behavior different from throw-catch construct discussed in class, where handlers go into a dynamic environment? If so, write down a new set of standard semantics which will make programs behave in a manner similar to the above example.