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,16 @@
=================================================================
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 inheritance.loader utility
file (note that the *.loader files are Prolog files).
This folder contains examples of public, protected and private inheritance,
for both prototypes and classes/instances. The category "predicates" defines
a set of three predicates, one public, one protected and one private. This
category is imported by the root objects: "parent" for the prototypes and
"object" for the classes/instances. Each root object have a set of three
descendants, each one using one of the inheritance types.

View File

@@ -0,0 +1,98 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% parent interface
| ?- parent::interface.
public/0 - public
protected/0 - protected
private/0 - private
interface/0 - public
yes
% prototype1 extends public::parent
| ?- prototype1::interface.
interface/0 - public
public/0 - public
protected/0 - protected
yes
% prototype2 extends protected::parent
| ?- prototype2::interface.
interface/0 - public
public/0 - protected
protected/0 - protected
yes
% prototype3 extends private::parent
| ?- prototype3::interface.
interface/0 - public
public/0 - private
protected/0 - private
yes
% object (root of the inheritance graph) interface
| ?- root::interface.
public/0 - public
protected/0 - protected
private/0 - private
interface/0 - public
yes
% instance1 instantiates subclass1 that specializes public::root
| ?- instance1::interface.
interface/0 - public
public/0 - public
protected/0 - protected
yes
% instance2 instantiates subclass2 that specializes protected::root
| ?- instance2::interface.
interface/0 - public
public/0 - protected
protected/0 - protected
yes
% instance3 instantiates subclass3 that specializes private::root
| ?- instance3::interface.
interface/0 - public
public/0 - private
protected/0 - private
yes

View File

@@ -0,0 +1,18 @@
:- initialization(
logtalk_load([
predicates,
interface,
parent,
prototype1,
prototype2,
prototype3,
root,
subclass1,
subclass2,
subclass3,
instance1,
instance2,
instance3])).

View File

@@ -0,0 +1,6 @@
:- object(instance1,
instantiates(subclass1)).
:- end_object.

View File

@@ -0,0 +1,6 @@
:- object(instance2,
instantiates(subclass2)).
:- end_object.

View File

@@ -0,0 +1,6 @@
:- object(instance3,
instantiates(subclass3)).
:- end_object.

View File

@@ -0,0 +1,22 @@
:- category(interface).
:- public(interface/0).
:- mode(interface, one).
interface :-
forall(
(::current_predicate(Functor/Arity),
functor(Pred, Functor, Arity)),
(::predicate_property(Pred, Prop), scope(Prop),
writeq(Functor/Arity), write(' - '), writeq(Prop), nl)).
scope(public).
scope(protected).
scope(private).
:- end_category.

View File

@@ -0,0 +1,6 @@
:- object(parent,
imports(predicates, interface)).
:- end_object.

View File

@@ -0,0 +1,25 @@
:- category(predicates).
:- public(public/0).
:- mode(public, one).
:- protected(protected/0).
:- mode(protected, one).
:- private(private/0).
:- mode(private, one).
public :-
write('Public predicate declared and defined in category predicates.'), nl.
protected :-
write('Protected predicate declared and defined in category predicates.'), nl.
private :-
write('Private predicate declared and defined in category predicates.'), nl.
:- end_category.

View File

@@ -0,0 +1,7 @@
:- object(prototype1,
imports(interface),
extends(public::parent)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(prototype2,
imports(interface),
extends(protected::parent)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(prototype3,
imports(interface),
extends(private::parent)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(root,
imports(predicates, interface),
instantiates(root)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(subclass1,
imports(interface),
specializes(public::root)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(subclass2,
imports(interface),
specializes(protected::root)).
:- end_object.

View File

@@ -0,0 +1,7 @@
:- object(subclass3,
imports(interface),
specializes(private::root)).
:- end_object.