This document describes Prolog++, an expressive and powerful object-oriented programming system, which combines the best of AI and OOPs.
Prolog++ - AI meets OOPs
Prolog++ is a full object-oriented system integrated within a Prolog framework. Objects and instances provide a convenient way to structure related pieces of knowledge and data. An object (or class) hierarchy allows information to be defined at the highest relevant level and be inherited through the taxonomy. This distributes data and functionality along a line from the general to the specific. By segmenting information with this approach, complex data relationships can be managed with efficiency. The ability to define object taxonomies with Prolog++ and manipulate them with Prolog rules provides a powerful combination for serious programmers.
Programming languages can be roughly split between the traditional approach which describes a program as a collection of algorithms and procedures which manipulate data, and the object-oriented approach which maps data directly onto objects which have the capability of communicating with each other.
The traditional approach can be further classified into procedural languages, such as Cobol, C, etc,. and declarative languages such as Prolog. Each approach has its benefits and its drawbacks.
One of the first object-oriented languages to be developed was Smalltalk, in which everything (including all integers, reals and identifiers) is considered to be an object. The emerging languages, such as C++, combine features of traditional languages with the object-oriented approach. C++ inherits characteristics of both approaches.
Prolog++ follows the lead of C++, but whereas C++ combines a procedural language with OOPS, Prolog++ combines a declarative language with OOPS. Prolog++ inherits the problem solving and database characteristics of Prolog, and also inherits the sound methodology of an OOPS approach.
Class hierarchies and inheritance
Class hierarchies are implemented by denoting within an class who its parents are. The inheritance of methods and attributes is governed by this relationship. Prolog++ supports multiple inheritance by multiple declarations of parenthood.
Prolog++ supports both static and dynamic objects. Dynamic objects can be created or augmented at run-time, while static objects are fixed and optimized at compile time.
Classes and Instances
A class is a template which defines the general characteristics of its instances and those of any of its sub-classes, sub-sub-classes etc.
Polymorphism and message passing
Prolog++ supports the use of different methods in different classes which can handle the same message. This follows the common view of polymorphism.
Prolog++ provides the ability to broadcast messages in the following ways:
- A single message to a group of instances
- A group of messages to a single instance
- A group of messages to a group of instances
Encapsulation and abstraction
Class definitions in Prolog++ are delimited by key words for their beginning and ending. All the methods and attributes within these two statements are encapsulated. The name of the class and the names of any public methods and attributes form the abstract of that class. Methods are implemented as Prolog clauses, and can be viewed or edited from within the base Prolog environment. Methods can be defined as public or private, have multiple definitions and be truly dynamic, i.e. they can be augmented at run-time.
The paradigm of data-driven programming is expressed in Prolog++ by the use of specific methods. Within Prolog++ there are four kinds of events which may cause a handler to be invoked. These are:
- create a new class instance
- delete an existing class instance
- assign a new value to a class/instance attribute
- raise a program exception
Copyright © 2019 LPA Ltd
All rights reserved