Out: November 27, 2007
Due: December 4, 2007
Because of html issues, I use + to start and end a part name. A = +b+ B. is a class with one part called b. In your program you use the normal class dictionary syntax.
For the purpose of type checking, we can translate A ~ {B}. into A = +element+ B. and also A = [+b+ B]. into A = +b+ B. This can be done easily with a preprocessor in DemeterF.
Example:
  Object : Exp | String | Integer.
  Exp : Lambda | Var.
  Lambda = +arg+ String [+body+ Exp] .
  Var : Sym | Addr.
  ExpList ~{Exp}.
is translated into:
  Object : Exp | String | Integer.
  Exp : Lambda | Var.
  Lambda = +arg+ String +body+ Exp .
  Var : Sym | Addr.
  ExpList = +element+ Exp .
Implement a type checker for CDS.
Input: A container C. Output: A container C' with no capacity violations plus a list of surplus items S. C' and S contain the same elements. If the surplus list is not empty for a container then adding any element from the list to the container would bring the container over capacity. (In other words, elements are put on the surplus list only when needed.)
A concrete class B translates into (define-datatype B B? [a-B parts]). An abstract class C translates into (define-datatype C C? [a-alt1 (contents alt1?)] ...).
Example:
Class dictionary:
PathSpec : Simple | Join | Merge.
Simple =  +source+ Node +target+ Node.
Join = +first+ PathSpec +second+ PathSpec .
Merge = +first+ PathSpec +second+ PathSpec .
Test = +simple+ Simple +join+ Join +merge+ Merge.
Datatypes:
(define-datatype path-spec path-spec?
   [a-simple (contents simple?)]
   [a-join (contents join?)]
   [a-merge (contents merge?)])
(define-datatype simple simple?
   [simple (source symbol?)
           (target symbol?)])
(define-datatype join join?
   [join (first path-spec?)
         (second path-spec?)])
(define-datatype merge merge?
   [merge (first path-spec?)
          (second path-spec?)])
define-datatype test test?
   [test
        (simple simple?)
        (join join?)
        (merge merge?)])
Use a ToString class similar to the one in
http://www.ccs.neu.edu/research/demeter/DemeterF/FuncTest.java
because it is a simple linear translation.
Last modified: November 28, 2007 by Karl Lieberherr