page 1  (12 pages)
2to next section

Chapter V

An implementation in Smalltalk

Since most constraint programming languages are semantically and sometimes also syntactically different from object-oriented languages, they are often implemented as new languages with own compilers or interpreters. These languages are usually not designed to be used for including constraints in existing application programs. This means that existing class libraries such as graphics libraries, application frameworks, etc., cannot be reused, if they are not implemented in a particular constraint language.

The language COPE is designed to be a constraint programming extension of existing imperative object-oriented languages. The language as described in the previous chapters can be most directly implemented in languages that support high-order language constructs so that programs can be treated as data. The experimental implementation described in this chapter is an example of such an extension. The implementation not only supports existing classes, but also the programming environment, since the extension itself is implemented as a class library. Syntactically, the extension follows the Smalltalk-80 language.

The appendix contains a list of classes and operations in COPE.

5.1. Overview of the implementation

The current implementation is based on the following ideas:
? A data-structure called cell is used in the implementation. A cell is an object which contains a number, boolean, character or other type of value. Cells are used to implement variables of basic datatypes. The original variables in Smalltalk are used as pointer variables.
? Symbolic evaluation of function expressions containing cells is implemented using instance methods on cells. These methods return objects representing symbolic expressions instead of values. Primitive constraints are implemented as instance methods on symbolic expressions. Function ex-