10.13.4 Term Classes

Sometimes it is convenient to be able to send messages to ordinary Prolog terms as if they were objects. Prolog terms are easier to create than objects, and unlike objects, they are automatically garbage collected (see obj-tech-lim). Of course, unlike objects, Prolog terms cannot be modified. However, when a particular class of objects never needs to be dynamically modified, and doesn't need to be subclassed, it may be appropriate to define it as a term class.

A term class is defined much like an ordinary class: it begins with a `:- class' directive defining the class and its slots, follows with clauses defining the methods for this class, and ends with an `:- end_class' directive, the end of the file, or another `:- class' directive. The only difference is in the form of the `:- class' directive introducing a term class definition.

Send feedback on this subject.