Pluto TOOLS01

You might also like

Download as ps, pdf, or txt
Download as ps, pdf, or txt
You are on page 1of 10

In Proceedings of the 39th International Conferences on Technology ofObject-Oriented Languages &

Systems (TOOLS USA 2001) Santa Barbara, USA, July 29-August 3, 2001. IEEE-CS Press, pp. ??-??.

Pluto: An Obje t-Oriented Logi Programming Language

Meng hi Liu
S hool of Computer S ien e, Carleton University, Ottawa, Canada
meng his s. arleton. a

Abstra t

The obje t-oriented philosophy reates a powerful synergy throughout the development life y le by
ombining abstra tion, en apsulation, and modularity. However, existing obje t-oriented program-
ming languages are low-level pro edural ones that are hard to program and debug. Logi programming
allows omputing problems to be expressed in a high-level de larative way, without giving instru -
tions for how the problem is to be solved. However, logi programming la ks powerful methods to
model appli ations. In the past de ades, the integration of obje t-oriented programming and logi
programming has attra ted a lot of interests with a number of languages proposed. But these lan-
guages fail to address some key obje t-oriented features properly. In this paper, we introdu e a novel
obje t-oriented logi programming language that supports nearly all obje t-oriented features in a logi
programming framework. We also des ribe its operational semanti s.

1 Introdu tion
Obje t-oriented programming and logi programming are two independently developed areas in
Computer S ien e. They o er better programming te hnologies than traditional pro edural-based
approa h. Logi programming began in the early seventies as a dire t outgrowth of earlier work
in automated theorem proving and arti ial intelligen e [10℄. Logi programming is based on rst-
order logi , formalized in terms of proof theory and model theory. Proof theory provides formal
spe i ations for orre t reasoning with premises, while model theory analyses how general assertions
may be interpreted with respe t to a olle tion of spe i fa ts. First-order logi was not used in
programming a tual appli ations until the introdu tion of Prolog, a language for PROgramming
in LOGi . Prolog uses a restri ted form of more general theorem proving te hniques to provide
eÆ ien y and programmability. It allows omputing problems to be expressed in a de larative way,
without giving instru tions for how the problem is to be solved.
Begun in late sixties, obje t-oriented programming is now the most popular programming paradigm.
Obje t orientation is a strategy for organizing systems as olle tions of intera ting obje ts that om-
bine data and behavior. The obje t-oriented philosophy reates a powerful synergy throughout the
development life y le by ombining abstra tion, en apsulation, and modularity. Abstra tion lets us
fo us on essential aspe ts of an appli ation while ignoring details. En apsulation separates external
spe i ation from internal implementation. Modularity promotes oheren e, understandability, and
symmetry by organizing a system into groups of losely related obje ts.
In the past few years, the integration of obje t-oriented and logi programming has attra ted
great interests. The obje tive is to gain the best of both approa hes. Various methods of in or-
porating obje t-oriented programming into Prolog have been dis ussed [5, 13, 14℄. Also, a number
of novel languages have been proposed su h as OOLP [3℄, C-Logi [2℄, L&O [11℄, Prolog++ [12℄,
COMPLEX [4℄, LIFE [1℄ and some of them have been implemented. However, none of them support
all important obje t-oriented features.
In this paper, we des ribe Pluto, an obje t-oriented logi programming language that supports
nearly all obje t-oriented features in a logi programming framework, su h as obje t identity, om-
plex obje ts, lass de nitions, typing, lause-based methods, en apsulation of data and methods,
information hiding, overloading, late binding, polymorphism, lass hierar hy, and non-monotoni
multiple stru tural and behavioral inheritan e with overriding, blo king and on i t handling.
Pluto takes many features from ROL2 [8℄ and Java. Unlike ROL2 whi h is intended to be mainly
a database query language, Pluto is intended to be a general programming language and in ludes
many programming related features not in ROL2, su h as Input/Output, Constru tors, a novel way
to obje t reations, Prolog way of assignments, dot notations and thus more like Java and Prolog.
It has two major goals: to support in a lause-based framework whatever obje t-oriented languages
an support but at a higher on eptual and de larative level so that programming an be ome easier
as many low-level pro edural onstru ts are no longer needed; and to support in an obje t-oriented
fashion whatever logi programming languages an support.
The paper is organized as follows. Se tion 2 introdu es types, values and lasses in Pluto. Se tion
3 dis usses non-monotoni multiple inheritan e in Pluto. Se tion 4 shows how to use Pluto and how
to program in Pluto. Se tion 5 on ludes the paper.

2 Types and Values


A type in Pluto denotes a olle tion of values. There are four kinds of types in Pluto: primitive
data types, lass types, list types and set types.
The primitive data types are built-in and in lude integer, real, har, string, and void. The values
that they denote are as follows: integer, real, har, string denote the sets of integers, real num-
bers, hara ters, and strings that an be represented in the system; void denotes the singleton set
onsisting of nil.
Class types denote olle tions of obje ts. Classes must be de ned using lass de nitions that
are introdu ed in the next se tion. For example, we may de ne the following lass types: person,
student, employee, dept. Obje ts in the olle tions that the lasses denote are alled instan es of the
lasses. They are reated with the new operator. See Se tion 5.
Set types are used to denote olle tions of homogeneous sets; that is, sets of the same type. For
example, fintegerg is a set type that denotes sets of integers; fpersong is set type that denotes sets
of persons if person is a de ned lass.
List types are used to denote olle tions of homogeneous lists. For example, (integer), (person)
are two examples of list types.
Pluto is an obje t-oriented logi programming language. Various lasses an be de ned with lass
de nitions whi h have the following form:
[abstra t℄ lass [isa 1 ; ::::; n ℄[ attribute de nitions method de nitions ℄
where is the lass to be de ned, 1 ; :::; n with n  0 are existing lasses, attribute de nitions
spe ify the stru ture of the lass and method de nitions spe ify the behavior of the lass. Whatever
is in [...℄ is optional. We dis uss the meaning of isa in the next se tion.

2.1 Attribute De nitions


Obje ts may have attributes through whi h they are related to ea h other. The attributes
appli able to all instan es of a lass, alled instan e attributes, must be de lared on the lass. The
instan e attribute de nition in Pluto has the following form:
[publi jprivate℄[instan e℄ a )  [default v ℄;
where a is an attribute,  is a type and v is a value. It spe i es that a is a partial mapping from
the lass type de ned to the type  su h that if the values for the attribute a are not given for the
obje t, then the default value v is used automati ally.
Consider the following example:
lass person [ birthyear) integer(1900..2000) default 1970 ; spouse ) person;
gender ) har(f'M', 'F'g) default 'F'; parents ) fpersong ℄
It de lares attributes birthyear, gender, spouse and parents to be partial mappings from lass person to
primitive data types integer(1900..2000) and har(f'M','F'g), itself, and set type fpersong respe tively
and if the values for the attribute birthyear and gender are not given, then the default values are
used automati ally.
If bob and pam are the names of two instan es of person, then bob.birthyear ! 1960 and
pam.spouse ! bob spe ify that the obje t referen ed by bob has value 1960 for the attribute birthyear
and the obje t referen ed by pam has the referen e of obje t named by bob as the value of the at-
tribute spouse. They are well-typed with respe t to the attribute de larations. But we annot have
both bob.birthyear ! 1960 and bob.birthyear ! 1950 as birthyear is a mapping. In other words, the
attribute values need to be unique. Also, the attribute values of some obje ts an be unknown as
attributes are partial mappings. Su h attributes are instan e attributes as only instan es of the
lass an have them.
We an query instan e attribute values as follows:
?{ pam.spouse ! S, S.birthyear ! B.
Pluto also supports the traditional dot notation for navigation. Formally o:a1 :a2 :::an ! X means
o:a1 ! X1 , X1 :a2 ! X2 , ... Xn 1 :an ! X . Thus, the above instan e attribute value query an
also be represented in Pluto as follows:
?{ pam.spouse.birthyear ! B.
If a lass has several attributes de ned on the same type: a1 )  , ..., an )  , then we an
ombine them into a1 ; :::; an )  . The following is an example:
lass point [ x, y ) real ℄
One of the key features of obje t-oriented paradigm is information hiding. That is, the a ess to
attribute values an be ontrolled. In Pluto, we an use the modi er private to indi ate that de ned
attribute annot be a essed dire tly while its omission (i.e., default) or use of publi indi ates that
the attribute an be a essed dire tly from the outside.
Consider the following example:
lass employee [name ) string; private salary ) integer ℄
For an instan e of the lass, the name attribute an be dire tly a essed while the salary attribute
annot.
The private attributes an be a essed indire tly by methods to be introdu ed later.
In Pluto, lasses an also have attributes. We use the quanti er stati like in Java and C++ to
indi ate that de ned attribute is a lass attribute, whereas its omission indi ates it is an instan e
attribute. Thus, the lass attribute de nition in Pluto has the following form:
[publi jprivate℄ stati a )  [default v ℄;
where a is the name of the lass attribute and  is a type. It spe i es that a is a partial mapping
that maps the de ned lass to an instan e of the type  .
Consider the following example:
lass person [ name ) string; age ) integer;
stati ount ) integer default 0; stati thisyear ) integer default 2000 ℄
where the rst two attributes are instan e attributes and the rest are lass attributes. In Pluto,
we an use lass attributes to represent onstants needed by the lass as shown by thisyear. For an
instan e attribute, ea h instan e of the lass has its own attribute while for a lass attribute, only
the lass de ned has the attribute, whi h is a essible from the instan es of the lass.
Like instan e attributes, a ess to lass attributes an also be ontrolled with the modi ers publi
and private. The default is publi while the use of private disallows the dire t a ess.
For publi lass attributes, we an dire tly a ess them using the lass. For example, we an
issue the following queries:
?{ person. ount ! X. ?{ person.thisyear ! X.
We an also dire tly a ess them using an instan e of the lass. For example, if bob referen es
an instan e of person, then the following queries give the same result as the above ones:
?{ bob. ount ! X. ?{ bob.thisyear ! X.
2.2 Methods
Obje t an be manipulated with methods. Pluto supports two kinds of methods: instan e meth-
ods and lass methods.
2.2.1 Instan e Methods
Instan e methods are the methods used to manipulate obje ts of a lass. They must be de ned
on the lass and en apsulated in the lass de nitions. An instan e method in Pluto onsists of two
parts: type de nition and implementation and has the following form:
[publi jprivate℄ op(1 ; :::; n ) )  f rule de nitions g
where op(1 ; ::; n ) )  is the type de nition whi h spe i es the name op of the method, the
argument types 1 ; :::; n that the method takes, and the result type  and instan e an be omitted.
In parti ular op(1 ; ::; n ) is alled the signature of the method and has to be unique within the
lass. When  is void, we an simply omit it and use op(1 ; :::; n ) instead; when n = 0, we have
to use op() )  to di erentiate it from attributes. The rule de nitions form the implementation of
the method.
We an lassify instan e methods in Pluto into ve kinds: input/output, dedu tion, updates,
onstru tor and obje t reation.

Input/output In Pluto, two primitive input/output ommands are provided: write and read like
in Prolog. The following lass de nition ontains the input/output methods
lass person [ birthyear ) integer; gender ) har('M','F');
showPerson() f showPerson() :{ birthyear ! B, gender ! G,
write("The birth year is " + B), write("The gender is " + G) g℄
where + is a string on atenation operation as in Java.
Note that in the above showPerson method, we have to use variables B and G to bind birthyear
and gender. From programming point of view, it is umbersome however. For this reason, Pluto
allows the user to use attribute names to stand for attribute values. For example, the rule in the
above showPerson method an also be written in Pluto as follows:
showPerson() :{ write("The birth year is " + birthyear), write("The gender is " + gender)

Instan e methods an only be invoked through instan es. For example, if bob referen es an
instan e of person, then the following query invokes the showPerson method:
?- bob.showPerson()

In Pluto, more spe i methods for input/output are provided in the lass system su h as readInt,
, , , , , ,
readReal readChar readString writeInt writeReal writeChar writeString.
Dedu tion Pluto is a logi programming language. It is mainly used to derive information that
is not expli itly available. Consider the following lass de nition.
) integer; parents) fpersong; stati thisyear ) integer default 2000;
lass person [ birthyear
age()) integerf age() ! A :{ A = thisyear - birthyearg
an estors()) fpersong f an estors()! hXi:{ parents ! hXi;
an estors()! hXi:{ parents ! hPi, P.an estors() ! hXig ℄

The rst method derives the age of a person from the birthyear. The se ond method derives
an estors from the attribute parents re ursively. The onstru t hX1 ; :::; Xn i is taken from ROL [6℄
and RLOG [7℄ for set manipulations. It fun tions in two di erent ways: it denotes a subset of the
set when used in the body of the rule and it is used to group a set when used in the head.
In Pluto, method type de nition and implementation an be tightly oupled. For example, the
above lass de nition an also be written like the one in Java:
lass person [ birthyear) integer; parents) fpersong; stati thisyear ) integer default 2000;
age() ) integer A f A = thisyear - birthyearg
an estors() ) fpersong hXif parents ! hXi; parents ! hXi, an estors() ! hXig ℄
Like Prolog, rules in Pluto are exe uted non-deterministi ally. fail and ! ( ut) an be used to
ontrol the exe ution of the rules.

Updates Attribute values of an obje t may hange over the time. Like Prolog whi h resorts to
and retra t for updates, Pluto uses
assert insert and delete for updates. The following methods
demonstrate updates in Pluto:
lass person [ spouse ) person;
marry(person) f marry(S) :{ not spouse ! , insert spouse ! S, insert S.spouse ! Self g
divor e() f divor e() :{ delete spouse ! S, delete S.spouse ! g℄
As the above example shows, always using delete and insert operations is low level and umber-
some. In Pluto, we an use the is operation for assignments instead. For example, the above two
methods an also be written as follows:
marry(person S) f not spouse ! , spouse is S, S.spouse is Self g
divor e() f spouse.spouse is null, spouse is null g℄
More formally, A is V in Pluto has the following meanings:
(1) if A is not an instan e variable, then it means ompute V and store the result in A; otherwise,
(2) if V is null, then it means delete A ! , otherwise,
(3) if V does not ontain A, then it means insert A ! V , otherwise,
(4) if V ontains A and assume X does not o ur in V , then it means delete A ! X , insert A !
V 0 where V 0 is obtained from V by repla ing A with X .

Constru tor When an instan e is reated, it is usually desirable to perform some initialization
a tion to setup its attribute values. In Pluto, we an use onstru tors for this purpose. A onstru tor
is a method that has the same name as the lass. Consider the following example:
) integer; gender) har(f'M','F'g); stati ount) integer default 0;
lass person [ birthyear
person(integer B)) f ount is ount + 1, birthyear is B g
person(integer B, har G)) f ount is ount + 1, birthyear is B, gender is G g ℄

This lass has two onstru tors that take di erent input values.
Unlike methods other than onstru tors, onstru tors are exe uted whenever an obje t of the
lass is reated. Consider the following query:
?{ liz = new person(1950).

It reates a new person obje t and binds the obje t to the name liz , and assigns the value 1950
into the orresponding attribute and in reases the ount of the obje ts in the lass by invoking the
onstru tor. Note here no value is provided for the attribute gender. As a result, the system assigns
the default value F to the attribute. In order to hange the value of gender later, we have to use
both delete and insert as shown in the update methods part.
If su h a onstru tor is not de ned in the lass de nition, then we have to use the following
queries and updates to a hieve the same result:
?{ liz = new person(). ?{ liz. ount is liz. ount + 1 .
Note that Pluto does type and onsisten y he king automati ally. Consider the following query
and update:
?{ pam = new person(1952, "Female"). ?{ liz.birthyear is 1952.

The system will tell that "Female" is not hara ter for the rst one and indi ate liz already has a
value for attribute birthyear for the se ond.

Obje t Creation In Pluto, obje ts an be reated in two di erent ways. One is using the obje t
reation methods. The other is using queries as shown above or using Pluto programs. We dis uss
the latter in detail in Se tion 4.
Consider the following lass de nition:
) integer(1..31); month) integer(1..12); year) integer(1950..2050);
lass date [ day
f day is D, month is M, year is Y g
date(integer D, integer M, integer Y)
opy() ) date N f day ! D, month ! M, year ! Y, N = new date(D, M, Y) g ℄

In this example, date is a onstru tor and opy is an obje t reation method.
2.2.2 Class Methods
Like attributes, methods in Pluto an also be lass ones. A lass method has the following form
in Pluto:
stati op (1 ; :::; n ) )  f rule de nitions g

where op(1 ; ::; n ) )  is the method type whi h spe i es the name op of the method, the argument
types 1 ; :::; n that the method takes, and the result type  . In parti ular op(1 ; ::; n ) is alled the
signature of the method and has to be unique within the lass. We an omit  if it is void.
The following is an example:
lass person [ name ) string; stati ount ) integer default 0;
stati showCount() f showCount() :{ ount ! C, write(C)g ℄
Class methods an only use lass attributes but not instan e attributes within the lass. Instan e
methods, however, an use both lass attributes and instan e attributes in any lass.
Like lass attributes, lass methods an be invoked through the lass. For example, we an issue
the following query:
?{ person.showCount().

Class methods an also be invoked through the instan es. We an have the following query whi h
generates the same result as the previous one.
?{ bob.showCount().

2.3 Method Overloading and Polymorphism


In Pluto, a name an be used for several methods with di erent signatures in the same lass; that
is, the name an be overloaded. Method overloading is a way to realize polymorphism. Consider
the following lass de nition:
lass person [ parents) fpersong;
hildren()) fpersong f hildren() ! hCi:{ C.parents ! hSelfig
hildren(person) ) fpersong f hildren(P) ! hCi:{ C.parents ! fSelf,Pgg ℄

where the rst method is used to obtain the hildren of a person while the se ond is used to obtain
the ommon hildren of two persons, one denoted by Self and the other by P. The name hildren is
overloaded in these two methods.
Like attributes, the use of methods other than onstru tors an also be ontrolled with the
modi ers publi and private. The default is publi while the use of private disallows the dire t use
and is mainly for intermediate methods. The onstru tors are always publi .

3 Class Hierar hy and Inheritan e


In Pluto, we an organize lasses into a lass hierar hy with the two built-in lasses obje t and
none at the top and bottom respe tively by using dire t sub lass/super lass de nitions and take
advantage of non-monotoni multiple stru tural and behavioral inheritan e.
A sub lass in Pluto inherits all instan e attributes, their default values, and methods of its dire t
super lasses with their a essibility. It an also introdu e additional attribute de nitions, default
values, and methods lo al to itself. Additionally, every instan e of a sub lass is a non-dire t instan e
of its super lasses.
Consider the following lass de nition:
lass employee isa person [ salary ) real default 1000; raise(real R) f salary is salary+salary*Rg℄
It says that employee is a sub lass of person. Therefore, employee inherits all instan e attribute
de nitions, default values, and methods from person. In addition, it also has its own attribute
de laration salary, default value for salary, and method raise. Every instan e of employee is also a
non-dire t instan e of person.
For dire t sub lasses of obje t, we an omit obje t in the lass de nition. For example, the lass
person an be de ned in two di erent ways in Pluto:

lass person isa obje t [...℄ or lass person [...℄

3.1 Inheritan e with Overriding and Blo king


In Pluto, a sub lass an also override or blo k attribute de nitions, default values and methods
inherited from its super lasses.
Consider the following two lass de nitions:
lass patient [ treatedBy ) physi ian℄
lass al oholi isa patient [ treatedBy ) psy hiatrist ℄
The rst one says patients are treated by physi ians. The se ond says al oholi s are patients
but are treated by psy hiatrists. However, psy hiatrists usually are not physi ians. The sub lass
al oholi introdu es a new de nition for attribute treatedBy whi h overrides the attribute de laration
treatedBy and the orresponding default value inherited from patient.
The following example shows how to override default values without overriding attribute de ni-
tions.
lass student isa person [ birthyear default 1975; gender default 'M'; takes ) f ourseg;
enroll( ourse)f enroll(C) :{ insert takes ! hCig
drop( ourse) f drop(C) :{ delete takes ! hCig℄

As a sub lass of person, student inherits all instan e attribute de nitions, default values and methods
of person. However, it has its default values for birthyear and gender whi h override the inherited
ones, its own attributes takes and methods drop and takes.
The next example shows how to blo k attribute and method inheritan e from a super lass.
lass elibate isa person spouse[ ) none; marry(person) ) none; divor e() ) none ℄

The built-in lass none is used here to blo k the inheritan e of the orresponding attribute and
methods from lass person to lass elibate so that instan es of elibate do not have a spouse and
annot use methods marry and divor e.
As Pluto supports method overloading, it is ne essary to spe ify the method signature for blo k-
ing. Also, attribute de nitions and their default values if any are bound together in terms of
inheritan e; that is, if a sub lass inherits an attribute de nition from a super lass, then it inherits
the default value if any for the orresponding attribute from the same lass if it does not override
it. If the attribute de nition is not inherited be ause of overriding, blo king or on i t handling
me hanisms to be dis ussed later, then the orresponding default value is also blo ked. Similarly,
when an attribute or method is not inherited, methods based on it may be ome ill-typed or even
result in run-time errors if they are inherited.
The Pluto system uses the dependen y relation to determine what an be inherited automati ally.

3.2 Non-Monotoni Multiple Inheritan e


Pluto supports multiple inheritan e. That is, a sub lass an be a dire t sub lass of more than
one super lass. Therefore, inheritan e on i ts may happen.
Consider the following lass de nitions:
lass employee [ ... ) string ℄
room
lass student [ ... room ) integer default 123 ℄
lass wstudent isa employee, student [ ℄

Here wstudent is a sub lass of employee and student. It inherits attributes and methods from both
employee and student and a on i t on the attribute room happens.
Unlike Java whi h only allows single inheritan e and C++ whi h prohibits on i ting properties
to be inherited, Pluto provides two di erent ways for on i t resolution: (1) user-spe i ed priority
and (2) inheritan e path sele tion, with user-spe i ed priority as the default me hanism:
User-Spe i ed Priority In Pluto, there is a built-in left-to-right ordering of super lasses in a
lass de nition. If two or more super lasses have the attribute de nitions and default values with
the same name or methods with the same signature either dire tly de ned or inherited, then the
one found in the lass appearing rst in the list is inherited.
Continuing with the previous example, wstudent automati ally inherits attribute room from em-
ployee rather than from student. It does not inherit the default value for room from student.
However, if two or more super lasses have methods with the same name but di erent signatures,
then all of them are inherited by the sub lass. In this ase, the method is just overloaded.
Inheritan e Path Sele tion If a sub lass needs to inherit one attribute de laration, default value,
or method from one super lass and another from a di erent super lass, then user-spe i ed priority
annot meet these demands. To solve this problem, Pluto allows the user to spe ify the inheritan e
path to override user-spe i ed priority using the from keyword.
Continue with the previous example of wstudent. Suppose that employee and student also have a
method in ome with same signature but di erent implementations. If we want wstudent to inherit
the attribute room and method in ome from student instead of employee, then we an use the
following lass de nition:
lass wstudent isa employee, student [ room, in ome() from student ℄
Note that with this lass de nition, wstudent inherits not only the attribute de laration but also
the default value of room from student. If the method in ome is overloaded in wstudent, only the
0-ary method is inherited with the above de nition.
4 Programming in Pluto
Programming in Pluto is like programming in other obje t-oriented programming languages:
writing various lasses that are needed for the appli ation and writing programs that use the lasses.
After de ning the lasses we need to use, we need to ompile ea h lass into its internal form for
optimal exe ution like in Java. The ompilation also handles inheritan e issues so that the lass in
its internal form ontains all the attributes, default values and methods, either dire tly de ned or
inherited.
The following are two omplete lass de nitions:
lass point [ x, y ) real;
point(real X, Y) f x is X, y is Yg
translate(point V) f x is x + V.x, y is y + V.yg
distan e(point V) ) real D f X is x - V.x, D = sqrt(XX + YY)g ℄
lass re tangle [ v1, v2, v3, v4 ) point;
re tangle(int X1, Y1, Y2, Y2, X3, Y3, X4, Y4) f v1 ! new point(X1,Y1),
v2 ! new point(X2,Y2), v3 ! new point(X3,Y3), v4 ! new point(X4,Y4)g
length() ) real Lf L is v1.distan e(v2)g
width() ) real Wf W is v1.distan e(v4)g
area() ) real Af A is length()width()g
translate(point V) f v1.translate(V), v2.translate(V), v3.translate(V), v4.translate(V)g ℄

When we have all the lasses we need, we an then use the Pluto system intera tively through
the Pluto ommand interpreter like Prolog. The rst thing we have to do is to load the lasses
we need to use into the main memory with the built-in method load in the built-in lass system.
On e the lasses are loaded into the memory, we an then use various ommands in Pluto to deal
with obje ts. There are four kinds of ommands in Pluto: (1) the obje t reation ommand new
to reate obje ts of some lasses in the main memory, (2) the obje t destroy ommand destroy to
delete obje ts from the main memory and release the spa e o upied by the obje ts, (3) the obje t
manipulation ommands insert and delete to manipulate attribute values, (4) the query ommands to
query attribute values and to invoke various methods. In fa t, we have already seen some ommands
in method de nitions in previous se tions.
Consider the following example:
?{ system.load(point). ?{ system.load(re tangle).
?{ p1 = new point(0,0). ?{ p2 = new point(1,1).
?{ r1 = new re tangle(0,0,0,1,1,0,1,1). ?{ write(r1.area()).
?{ r1.translate(v2). ?{ v1.destroy().

The rst two are query ommands that load two lasses into the main memory. The next three are
obje t reation ommands that reate two obje ts in the point lass and one obje t in the re tangle
lass and bind them to names p1, p2 and r1. The rest other than the last are all query ommands.
The rst one is used to display the area of the re tangle r1. The se ond performs translation of the
re tangle with respe t to point p2 The last one is an obje t destroy ommand whi h removes the
obje t p1 from the memory.
Note that in Pluto, some obje ts may have a name su h as p1, p2 and r1 above and obje ts may
not have a name su h that the point obje ts reated by the onstru tor of re tangle. Named obje ts
remain in the system until they are expli itly destroyed. Unnamed obje ts remain in the system
only if they are referen ed.
In Pluto, we an also put various ommands into a named program. A program in Pluto has a
following form: program N ame [ ommands ℄ For example, we an put the above ommands in a
program. whi h an be dire tly exe uted by the Pluto ommand interpreter in a non-intera tive
mode.
5 Con lusion
In this paper, we have des ribed Pluto, a de larative programming language that supports nearly
all obje t-oriented features in a logi programming framework and its operational semanti s. We
have shown that the two programming paradigms t together ni ely so that the best of the two an
be a hieved. Furthermore, we have provided the link between the two programming paradigms so
that the user an understand obje t-oriented programming from logi programming point of view
and logi programming from obje t-oriented point of view.
Like Prolog, programming in Pluto is mostly de larative. The power of Pluto an be easily
extended by developing various lasses like in Java, su h as graphi s, applets, and persistent data.
The Pluto system is urrently being implemented. We plan to make the system publi ally avail-
able over the Internet after further testing and debugging. Our obje tive is to develop a high-level
de larative programming language to ease the painful programming. To this end, we will add other
features and provide various built-in lasses to make Pluto a real general programming language.
The semanti s of Pluto has been partially investigated in [9℄. More general semanti s for Pluto is
urrently under resear hing.

Referen es
[1℄ H. Ait-Ka i and A. Podelski. Towards a Meaning of Life. Journal of Logi Programming,
16(3):195{234, 1993.
[2℄ W. Chen and D.S. Warren. C-Logi for Complex Obje ts. In Pro eedings of the ACM Sympo-
sium on Prin iples of Database Systems, pages 369{378, Philadelphia, Pennsylvania, 1989.
[3℄ M. Dalal and D. Gangopadhyay. OOLP: A Translation Approa h to Obje t-Oriented Logi
Programming. In W. Kim, J.M. Ni olas, and S. Nishio, editors, Pro eedings of the International
Conferen e on Dedu tive and Obje t-Oriented Databases, pages 593{606, Kyoto, Japan, 1989.
North-Holland.
[4℄ S. Gre o, N. Leone, and P. Rullo. COMPLEX: An Obje t-Oriented Logi Programming System.
IEEE Transa tions on Knowledge and Data Engineering, 4(4):344{359, 1992.
[5℄ K. Kahn, E.D. Tribble, M.S. Miller, and D. G. Bobrow. Obje ts in Con urrent Logi Program-
ming Languages. In OOPSLA '86 Pro eedings, pages 247{252. ACM New York, 1986.
[6℄ M. Liu. ROL: A Dedu tive Obje t Base Language. Information Systems, 21(5):431 { 457, 1996.
[7℄ M. Liu. Relationlog: A Typed Extension to Datalog with Sets and Tuples. Journal of Logi
Programming, 36(3):271{299, 1998.
[8℄ M. Liu. Overview of the ROL2 Dedu tive Obje t-Oriented Database System. In Pro eedings
of the 30th International Conferen e on Te hnology of Obje t-Oriented Languages & Systems
(TOOLS USA '99), pages 63{72, Santa Barbara, CA, USA, August 1-5 1999. IEEE-CS Press.
[9℄ M. Liu, G. Dobbie, and T. W. Ling. A Logi al Foundation for Dedu tive Obje t-Oriented
Databases. In Pro eedings of the 7th International Conferen e on Database Systems for Ad-
van ed Appli ations (DASFAA 2001), pages 116{125, Hong Kong, China, April 18-20 2001.
IEEE Computer So iety Press.
[10℄ J. W. Lloyd. Foundations of Logi Programming. Springer-Verlag, 2 edition, 1987.
[11℄ F. G. M Cabe. Logi and Obje ts. Prenti e Hall., 1992.
[12℄ C. Moss. Prolog++. Addison-Wesley, 1994.
[13℄ P. S ha hte and G. Saab. EÆ ient obje t-oriented programing in prolog. In Christoph Beierle
and Lutz Plumer, editors, Logi al Programming: Formal Methods and Pra ti al Appli ations,
Studies in Computer S ien e and Arti ial Intelligen e. Elsevier S ien e, 1995.
[14℄ E. Shapiro and A. Takeu hi. Obje t oriented programming in on urrent Prolog. New Gener-
ation Computing, 1:25{48, 1983.

You might also like