CS 536 (F02) Homework 4: Exceptions and Continuations

Due: October 15 in class (hardcopy) AND via turnin (assignment name hwk4).


Assignment Goals


Exercises: Implementing Exceptions

  1. The notes on exceptions explain how to add exceptions to our language. Start from the following basic interpreter with environments and add both if-statements and exceptions as outlined in those notes. You should be able to interpret the exception-based product program from the notes in your solution. Note that this means that you will also need to add recursion. Use the boxed-based approach from class on Oct 1.

    Do this in the spirit of the notes linked above. In particular, do not copy the CPS-based implementation of exceptions from the later notes -- that solution will get you no credit for this exercise.

    You should also include your own additional test cases.

Exercises: Working with Continuations

  1. The file mastermind.ss contains the Scheme code to play a simplified version of the game Mastermind. In Mastermind, one player picks a sequence of 5 colored pegs and the other player has to guess the peg colors (in order). After each guess, the first player indicates how many peg colors were correct. The game stops when the first player guesses the correct sequence.

    Convert the functions in the mastermind.ss file into CPS (all the user-defined functions minus match?, which you can treat as a primitive). Do not convert calls to functions other than those defined in the file (ie, treat any Scheme-defined functions as primitives). Include correct contracts on all of your converted functions.

    If your converted version is correct, a user should not see a difference between playing my original version and your new version (on the same inputs, of course).

    (Side note, not part of the assignment: if you want to have fun with the Scheme web server, look up web-server in the DrScheme help system and try to port the mastermind game to the web using send/suspend.)

Exercises: Implementing Let/cc

  1. The notes on continuation-passing style show the result of converting the environment-based interpreter to continuation-passing style (on page 4). Add a let/cc construct to this interpreter. As always, provide the test cases with which you tested your work.


Back to the Assignments page