Prolog realization

Instructor's Guide

Introduction Interface Broker C++ Java Prolog Configure Conclusions
Although Prolog is not a mainstream programming language in IT, it is interesting to look at the realization of the Hello Universe example in Prolog, if only to observe that its structure is very similar to the realization in Java and C++. In this example, that is implemented with the SWI-Prolog CORBA stubber, which generates most of the code, we will primarily look at the implementation of the server object itself. The relevance of this example may be motivated by the observation that many knowledge-intensive IT applications are realized by imperative (object-oriented) languages such as Java and C++ which are obviously not suited for that.

Prolog realization

slide: Prolog realization

For those that do not know Prolog it is sufficient to know that in Prolog so-called predicate definitions act as procedures, that may be invoked by trying to satisfy a goal. A special, very powerful, feature of Prolog is that
  broker(client(M:F)) :-
... corba_initialize_orb([], _), factory(F).
gives a handle to the server object
broker(server(M:I)) :- ... corba_initialize_server([server,server(test), timeout(infinite)],Server), ...
create server object
G =.. [_Create,_Server,Self], call(G), corba_object_to_string(Self,IOR), open(IORFile,write,Fd),
write reference to file
format(Fd,'string',[IOR]), close(Fd), corba_main_loop(Server).
enter main loop

slide: Prolog -- broker

Obviously, when looking at this code, some standardization of a CORBA binding for Prolog is desirable.


The client makes a connection with the broker, gets a binding to the server object and calls some methods of that object.
:- use_module(universe).
:- [broker].
include broker
main :- broker(client(universe:F)),
initialize the broker
assert(client(factory(F))), run. run :- h, ask('What is the state of Clinton s affairs?'), write('Type h to say hallo, x to quit.'),nl. ask(X) :- client(factory(F)), write(client(ask(X))),nl, world_ask(F,X), world_tell(F,R), write(client(ans(R))),nl. h :- client(factory(F)), world_hello(F). q :- client(factory(F)), world_halt(F), halt. x :- halt.

slide: Prolog -- client


The server is significantly simpler, due to the fact that all ugly details have been hidden in the broker.
  :- [broker].
main :- broker(server(universe:world)).

slide: Prolog -- server

The implementation of the server object consists of a collection of predicate definitions (procedures), that have the interface or class name as a prefix.

Prolog -- implementation

  :- module('universe',[]).
world_hello(_Self) :- write('Hello World'),nl. world_ask(_Self, X) :- write(asking(X)), nl. world_tell(_Self,Y) :- Y = 'logically, ok', write(telling(Y)),nl. world_halt(_Self) :- halt.

slide: Prolog -- implementation

As in the previous examples, the actual realization is admittedly simple.


Prolog, also in its standard (that is, non-object-oriented form) is a powerful language for implementing knowledge-intensive applications. This example shows that CORBA applications can be realized also by using Prolog technology. I would welcome seeing real-life applications in which the knowledge programming part was written in Prolog or an object-oriented extension thereof (such as the language DLP).