CSCI (Math) 361
I have written a Java library to support interaction with a datatype equivalent to the set DA in Jones. The files available are:
The library is of course written in an object-oriented style, but that should be a simple translation for you. I.e., rather than writing cons(a,b), you instead write b.cons(a) to generate an element with a as the head and b as the tail (be sure to get the order right!). The expressions a.hd() and a.tl() generate the head and tail of an element (which is nil if a is an atom). a.eq(b) determines if a and b are equal and returns the encoding, D.dTrue, of true if they are the same, and the encoding, D.dFalse, of false if they are different. Thus eq always returns an element of D. For convenience I also included the method booleq which returns a real (Java) boolean.
By the way, "nil" is no longer represented by Java's null. That means that there is no problem sending messages to nil. This makes your life much easier in writing programs.
Download the files, compile them all (use javac *.java in the directory with the files) and run the application TryJava (by typing java TryJava) to see how the application works. Feel free to use this to test out WHILE programs, though be sure only to use assignment, while, if-then-else, and sequencing in your programs. Feel free to extend the library to include support for the list notation introduced in class, as well as the number representations as lists.