Include Paulo Moura's Logtalk OO LP system

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@53 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2001-06-06 19:40:57 +00:00
parent 38247e38fc
commit cc4531cd1e
344 changed files with 27125 additions and 0 deletions

15
Logtalk/examples/mi/NOTES Normal file
View File

@@ -0,0 +1,15 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the mi.loader utility
file (note that the *.loader files are Prolog files).
There are two examples in this folder. The first one is an adoption of a
multi-inheritance C++ example found on the D. M. Capper book "Introducing
C++ for Scientists, Engineers and Mathematicians" published by
Springer-Verlag. It uses dynamic predicates for storing state. The second
example is a variant of the first using parametric objects.

View File

@@ -0,0 +1,89 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% set a point in the space-time:
| ?- space_time::rotate(1, 2, 3).
yes
| ?- space_time::translate(4).
yes
% verify it:
| ?- space_time::xyzt(X, Y, Z, T).
T = 4,
X = 1,
Y = 2,
Z = 3 ?
yes
% enumerate space_time public predicates:
| ?- space_time::(current_predicate(Functor/Arity), functor(Pred, Functor, Arity), predicate_property(Pred, declared_in(Object))).
Pred = xyzt(_A,_B,_C,_D),
Arity = 4,
Object = space_time,
Functor = xyzt ? ;
Pred = xyz(_A,_B,_C),
Arity = 3,
Object = space,
Functor = xyz ? ;
Pred = rotate(_A,_B,_C),
Arity = 3,
Object = space,
Functor = rotate ? ;
Pred = t(_A),
Arity = 1,
Object = time,
Functor = t ? ;
Pred = translate(_A),
Arity = 1,
Object = time,
Functor = translate ? ;
no
% get the origin distance from a point in the space-time(_, _, _, _):
| ?- space_time(2,3,4,7)::distance(D).
D = 5.385164807134504 ?
yes
| ?- space_time(2,3,4,7)::time(T).
T = 7 ?
yes
% enumerate space_time(_, _, _, _) public predicates:
| ?- space_time(2,3,4,7)::(current_predicate(Functor/Arity), functor(Pred, Functor, Arity), predicate_property(Pred, declared_in(Object))).
Pred = distance(_A),
Arity = 1,
Object = space(_B,_C,_D),
Functor = distance ? ;
Pred = time(_A),
Arity = 1,
Object = time(_B),
Functor = time ? ;
no

View File

@@ -0,0 +1,10 @@
:- initialization(
logtalk_load([
space,
space_time,
time,
space3,
space_time4,
time1])).

View File

@@ -0,0 +1,28 @@
:- object(space).
:- public(xyz/3).
:- mode(xyz(?integer, ?integer, ?integer), zero_or_one).
:- private(xyz_/3).
:- mode(xyz_(?integer, ?integer, ?integer), zero_or_one).
:- dynamic(xyz_/3).
:- public(rotate/3).
:- mode(rotate(+integer, +integer, +integer), zero_or_one).
xyz(X, Y, Z) :-
::xyz_(X, Y, Z).
rotate(X, Y, Z) :-
integer(X),
integer(Y),
integer(Z),
::retractall(xyz_(_, _, _)),
::assertz(xyz_(X, Y, Z)).
:- end_object.

View File

@@ -0,0 +1,16 @@
:- object(space(_X,_Y,_Z)).
:- public(distance/1).
:- mode(xyz(?nunber), one).
distance(Distance) :-
parameter(1, X),
parameter(2, Y),
parameter(3, Z),
Distance is sqrt(X*X+Y*Y+Z*Z).
:- end_object.

View File

@@ -0,0 +1,15 @@
:- object(space_time,
extends(space, time)).
:- public(xyzt/4).
:- mode(xyzt(?integer, ?integer, ?integer, ?integer), zero_or_one).
xyzt(X, Y, Z, T) :-
::xyz(X, Y, Z),
::t(T).
:- end_object.

View File

@@ -0,0 +1,6 @@
:- object(space_time(X, Y, Z, T),
extends(space(X, Y, Z), time(T))).
:- end_object.

View File

@@ -0,0 +1,26 @@
:- object(time).
:- public(t/1).
:- mode(t(?integer), zero_or_one).
:- private(t_/1).
:- mode(t_(?integer), zero_or_one).
:- dynamic(t_/1).
:- public(translate/1).
:- mode(translate(+integer), zero_or_one).
t(T) :-
::t_(T).
translate(T) :-
integer(T),
::retractall(t_(_)),
::assertz(t_(T)).
:- end_object.

View File

@@ -0,0 +1,13 @@
:- object(time(_T)).
:- public(time/1).
:- mode(time(?integer), zero_or_one).
time(Time) :-
parameter(1, Time).
:- end_object.