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

View File

@@ -0,0 +1,21 @@
=================================================================
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 polygons.loader utility
file (note that the *.loader files are Prolog files).
You will need to load the objects in the roots and relations
examples (consulting the corresponding roots.loader and relations.loader
files).
You will also need to consult the following files in the library directory:
events.loader, types.loader, metapredicates.loader, and hierarchies.loader.
In this example we have several types of polygons that can be concentric.
This is represented by a concentric binary relation ensuring that whenever
a polygon is moved towards a new position, all polygons likewise concentric
are moved along with them.

View File

@@ -0,0 +1,142 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% first create four polygons and move each one to a different position
| ?- triangle::new(t, [position-(4, 5)]).
yes
| ?- square::new(s, [position-(3, 2)]).
yes
| ?- pentagon::new(p, [position-(7, 1)]).
yes
| ?- hexagon::new(h, [position-(2, 4)]).
yes
% create two tuples of relation concentric
| ?- concentric::add_tuple([t, s]).
yes
| ?- concentric::add_tuple([p, h]).
yes
% check results
| ?- concentric::tuple(Tuple), write(Tuple), nl, fail.
[t,s]
[p,h]
no
| ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh).
Xh = 7,
Yh = 1,
Xp = 7,
Xs = 4,
Xt = 4,
Yp = 1,
Ys = 5,
Yt = 5
yes
| ?- after_event_registry::monitors(Ma).
Ma = [concentric]
yes
% move triangle to a new position
| ?- t::move(3, 3).
yes
% move the hexagon to a new position
| ?- h::move(8, 4).
yes
% check results
| ?- concentric::tuple(Tuple), write(Tuple), nl, fail.
[t,s]
[p,h]
no
| ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh).
Xh = 8,
Yh = 4,
Xp = 8,
Xs = 3,
Xt = 3,
Yp = 4,
Ys = 3,
Yt = 3
yes
| ?- after_event_registry::monitors(Ma).
Ma = [concentric]
yes
% create another tuple of relation concentric
| ?- concentric::add_tuple([t, p]).
yes
% move the pentagon to a new position
| ?- p::move(2, 7).
yes
% check results
| ?- concentric::tuple(Tuple), write(Tuple), nl, fail.
[t,s]
[p,h]
[t,p]
no
| ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh).
Xh = 2,
Yh = 7,
Xp = 2,
Xs = 2,
Xt = 2,
Yp = 7,
Ys = 7,
Yt = 7
yes
| ?- after_event_registry::monitors(Monitors).
Monitors = [concentric]
yes
% clean up instances, tuples and monitors
| ?- concentric::remove_all_tuples.
yes
| ?- triangle::delete(t).
yes
| ?- square::delete(s).
yes
| ?- pentagon::delete(p).
yes
| ?- hexagon::delete(h).
yes

View File

@@ -0,0 +1,69 @@
:- object(concentric,
instantiates(constrained_relation)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Concentric polygons as a constrained binary relation.']).
:- uses(list).
descriptor_([x1, x2]).
domain_(x1, polygon).
domain_(x2, polygon).
key_([x1, x2]).
cardinality_(x1, 0, n).
cardinality_(x2, 0, n).
delete_option_(x1, cascade).
delete_option_(x2, cascade).
add_tuple([Polygon| Polygons]) :-
Polygon::position(X, Y),
forall(list::member(Polygon2, Polygons), {Polygon2::move(X, Y)}),
^^add_tuple([Polygon| Polygons]).
activ_points_(x1, before, []).
activ_points_(x1, after, [move(_, _), transX(_), transY(_)]).
activ_points_(x2, before, []).
activ_points_(x2, after, [move(_, _), transX(_), transY(_)]).
propagate(after, move(X, Y), Polygon, _, Tuple) :-
list::select(Polygon, Tuple, Polygons),
!,
forall(
(list::member(Polygon2, Polygons),\+ Polygon2::position(X, Y)),
{Polygon2::move(X, Y)}).
propagate(after, transX(X), Polygon, _, Tuple) :-
list::select(Polygon, Tuple, Polygons),
!,
forall(
(list::member(Polygon2, Polygons), \+ Polygon2::position(X, _)),
{Polygon2::transX(X)}).
propagate(after, transY(Y), Polygon, _, Tuple) :-
list::select(Polygon, Tuple, Polygons),
!,
forall(
(list::member(Polygon2, Polygons), \+ Polygon2::position(_, Y)),
{Polygon2::transY(Y)}).
:- end_object.

View File

@@ -0,0 +1,20 @@
:- object(hexagon,
instantiates(class),
specializes(polygon)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Hexagon class.']).
number_of_sides(6).
instance_base_name(hex).
:- end_object.

View File

@@ -0,0 +1,20 @@
:- object(pentagon,
instantiates(class),
specializes(polygon)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Pentagon class.']).
number_of_sides(5).
instance_base_name(pen).
:- end_object.

View File

@@ -0,0 +1,71 @@
:- object(polygon,
instantiates(abstract_class),
specializes(object)).
:- info([
version is 1.1,
date is 2000/10/31,
authors is 'Paulo Moura',
comment is 'Polygon predicates.']).
:- uses(list).
:- public(move/2).
:- mode(move(+integer, +integer), one).
:- public(number_of_sides/1).
:- mode(number_of_sides(?integer), zero_or_one).
:- private(position_/2).
:- dynamic(position_/2).
:- mode(position_(?integer, ?integer), zero_or_one).
:- public(position/2).
:- mode(position(?integer, ?integer), zero_or_one).
:- info([
version is 2,
date is 1998/2/23,
authors is 'Paulo Moura',
comment is 'Default protocol for all polygons.']).
position(X, Y) :-
::position_(X, Y).
move(X, Y) :-
::retractall(position_(_, _)),
::assertz(position_(X, Y)).
trans_x(X) :-
::retractall(position_(_, Y)),
::assertz(position_(X, Y)).
trans_y(Y) :-
::retractall(position_(X, _)),
::assertz(position_(X, Y)).
default_init_option(position-(0, 0)).
default_init_option(Default) :-
^^default_init_option(Default).
process_init_option(position-(X, Y)) :-
::move(X, Y).
process_init_option(Option) :-
^^process_init_option(Option).
:- end_object.

View File

@@ -0,0 +1,9 @@
:- initialization(
logtalk_load([
concentric,
hexagon,
pentagon,
polygon,
square,
triangle])).

View File

@@ -0,0 +1,20 @@
:- object(square,
instantiates(class),
specializes(polygon)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Square class.']).
number_of_sides(4).
instance_base_name(sq).
:- end_object.

View File

@@ -0,0 +1,20 @@
:- object(triangle,
instantiates(class),
specializes(polygon)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Triangle class.']).
number_of_sides(3).
instance_base_name(tri).
:- end_object.