Quintus Prolog Homepage WELCOME TO
Quintus Prolog
The Industry Standard
  Quintus Home > Quintus Objects
Quintus Objects is another<BR>useful tool for Quintus Prolog

Quintus Objects is another
useful tool for Quintus Prolog

Prolog with Objects

Quintus Objects provides an efficient way for Prolog programmers to define and use objects in their programs.

In Quintus Objects, an object is a data structure that holds information and responds to commands, which are called messages. Each kind of object is a class. Every object is a member of exactly one class and is an instance of its class. Using Quintus Objects, programmers can create and send messages to objects in their Prolog programs.

A slot is a part of an object that holds data. In Quintus Objects, programmers may specify the type of a slot. The allowed types include the following:

  • 16-bit and 32-bit signed and unsigned integers
  • 8-bit signed and unsigned characters
  • 32-bit and 64-bit floating point numbers
  • Prolog atoms
  • Addresses, pointers and objects
  • Arbitrary Prolog terms

This allows programmers to specify a definite, C-style type, when appropriate. Or, programmers may choose to allow general Prolog terms in a slot, to take advantage of the flexibility of Prolog.

When an object is created, each slot is given an initial value based on its type. Numerical slots are initialized to 0, etc. Programmers may specify a different initial value, as part of the class definition. In addition to specifying its type and its initial value, programmers may also declare a slot to be private, which limits access to the slot.

A method defines how an object responds to a message. In Quintus Objects, methods are defined by Prolog clauses. Instances of a class are created and destroyed by that class's create and destroy methods. Other methods can access data in the object's slots, perform I/O, send their own messages to objects, etc.

Quintus Objects provides direct access to an object's slots, using its built-in fetch_slot/2 or store_slot/2 predicates. These allow the programmer to access and modify a slot's value without sending a message to the slot's object.

One of the most powerful features of object-oriented programming is inheritance. In Quintus Objects, if a new class is defined as a child (that is, a special case) of an existing class, it inherits the slots and methods of its parent class. The child class may add its own slots and methods, and it may redefine some of the slots and methods it inherits. Quintus Objects supports multiple inheritance, where a class may inherit from more than one parent class, and its uninherit directive can prevent the inheritance of individual methods.

Quintus Objects supports debugging with its debug_message directive. Either methods or ordinary Prolog code compiled with this directive raise Prolog exceptions, whenever a message is sent to an object that cannot "understand" it, or whenever either a message or its recipient are unbound Prolog variables.