CS 3520 Homework 11   - Due December 3

Exercise 11.1, Continuations

The following are possible states of the interepreter with continuations. In each case, what will the final value of the program be?
  1. exp: 3
    env: {}
    cnt: [primother -, 4, {}, [done]]

  2. exp: x
    env: {x=7, {x=4, {}}}
    cnt: [primother +, x, {x=4, {}}, [done]]

  3. val: 10
    cnt: [app <x, proc(y)*(y, 2), {x=8, {}}>, [apparg x, {x=8, {}}, [done]]]

  4. val: <x, proc(y)+(x, y), {x=9, {}}>
    cnt: [apparg 7, {x=9, {}}, [apparg x, {x=9, {}}, [done]]]

  5. val: <w, if w then (f proc(x)1) else w, {f=<g, *((g 3), 4), {}>, {}}>
    cnt: [app <g, *((g 3), 4), {}>, [done]]
Express your answer as a function answer-for-11.1 that takes no arguments and returns a list of 5 numbers.

Exercise 11.2, Exceptions

The following are possible states of the interepreter with exceptions. In each case, what will the final value of the program be, or which unhandled exception will it terminate with?
  1. val: 1
    cnt: [raise [done]]

  2. exp: 1
    env: {}
    cnt: [primother +, raise 3, {}, [done]]

  3. val: 0
    cnt: [if raise 1, 5, {}, [done]]

  4. exp: 5
    env: {}
    cnt: [handle <x, +(x, 1), {}> [prim +, 1, [done]]]

  5. exp: raise 5
    env: {}
    cnt: [handle <x, +(x, 1), {}> [prim +, 1, [done]]]

  6. val: 5
    cnt: [raise [handle <x, 7, {}> [handle <y, 8, {}> [done]]]]

  7. val: <y, 5, {}>
    cnt: [app <g, try (f 1) handle g, {f=<x, raise 1, {}>, {}}>, [done]]
Express your answer as a function answer-for-11.2 that takes no arguments and returns a list of 7 elements, where each element is a 2-element list, either '(val n) or '(exn n). An element should be '(val n) if its expression produces the number n, and it should be '(exn n) if its expression raises the unhandled exception n.

Exercise 11.3, First-Class Continuations [Extra Credit]

The following is a possible state of the interepreter with first-class continuations. What is the program's final answer?Express your answer as a function answer-for-11.3 that takes no arguments and returns a number.


Last update: Thursday, November 21st, 2002
mflatt@cs.utah.edu