CS 441 Assignment 8: Object Systems

This assignment is due in two weeks on thursday May 2 at 10:30am, by electronic submission, and is worth double points. This is the last assignment! Unlike previous assignments, this assignment is deliberately more vague. Use creativity and judgment in your solutions!

Read the lecture notes for background, and EOPL Chapter 7. Feel free to work from one of my solutions if you have trouble with yours.

Part 1

You are to add an object system to an interpreter for a Scheme-like language. You might extend your first-order interpreter for part 1 of assignment 3, or the interpreter from assignment 7 (strip out the type checking). Environments should map variables to boxes. Other parts of the interpreter may be meta-circular or first-order as required. Support at least the following language:

 e ::= n                  
     | #t                 
     | #f                 
     | ()                 
     | (quote x)          
     | x
     | (if e e e)         
     | (begin e ...)         
     | (lambda (x ...) e) 
     | (let ((x e) ...) e)
     | (letrec ((x f) ...) e)
     | (set! x e)
     | (e e ...)
     | (class ((x e) ...) ((x e) ...) ((x (x ...) e) ...) e)
     | (new e)
     | (send e x e ...)
where n is a number, x is a variable, f is a lambda expression, and ... means zero or more of the previous item.

The object facilities work as follows:

    (class ((x e) ...)             class variables and initial values
           ((x e) ...)             instance variables and initial values
           ((x (y ...) e) ...)     methods x with zero or more parameters y and body e
           e)                      super class

    (new e)                        create object of class e

    (send e1 x e2 ...)             send message x to object e1 with args e2 ...
Unlike the system presented in class, instance variables and class variables from superclasses should be available for access or mutation (via set!) in subclasses. You may wish to require that class variables and instance variables have special names to distinguish them from ordinary variables. Say, instance variable names start with "$", and class variables with something else. (You'll find symbol->string and string-ref to be useful procedures for this purpose.) Declare the name noclass in your top-level environment to be a class with no methods, so that classes without a superclass can inherit from noclass. Methods should be able to refer to this to access the current object.

Inheritance may be static or dynamic, your choice.

Part 2

Add some way of referring to superclass instance variables and methods when they are shadowed by subclass names.

Part 3

Do one of the following:

What to turn in

Turn in a single file that uses no load's other than cs441-load's and has no syntax errors. This file must have three parts: