From 47a547502417de4bc279646012e27fc297e2080d Mon Sep 17 00:00:00 2001 From: pmoura Date: Tue, 28 May 2002 11:35:10 +0000 Subject: [PATCH] Logtalk 2.12.0 files. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@495 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- Logtalk/examples/dynpred/NOTES | 13 ++++ Logtalk/examples/dynpred/SCRIPT | 91 +++++++++++++++++++++++++ Logtalk/examples/dynpred/class.lgt | 12 ++++ Logtalk/examples/dynpred/descendant.lgt | 6 ++ Logtalk/examples/dynpred/dynpred.loader | 9 +++ Logtalk/examples/dynpred/instance.lgt | 1 + Logtalk/examples/dynpred/metaclass.lgt | 6 ++ Logtalk/examples/dynpred/prototype.lgt | 42 ++++++++++++ Logtalk/examples/dynpred/root.lgt | 12 ++++ 9 files changed, 192 insertions(+) create mode 100644 Logtalk/examples/dynpred/NOTES create mode 100644 Logtalk/examples/dynpred/SCRIPT create mode 100644 Logtalk/examples/dynpred/class.lgt create mode 100644 Logtalk/examples/dynpred/descendant.lgt create mode 100644 Logtalk/examples/dynpred/dynpred.loader create mode 100644 Logtalk/examples/dynpred/instance.lgt create mode 100644 Logtalk/examples/dynpred/metaclass.lgt create mode 100644 Logtalk/examples/dynpred/prototype.lgt create mode 100644 Logtalk/examples/dynpred/root.lgt diff --git a/Logtalk/examples/dynpred/NOTES b/Logtalk/examples/dynpred/NOTES new file mode 100644 index 000000000..b98f8785d --- /dev/null +++ b/Logtalk/examples/dynpred/NOTES @@ -0,0 +1,13 @@ +================================================================= +Logtalk - Object oriented extension to Prolog +Release 2.12.0 + +Copyright (c) 1998-2002 Paulo Moura. All Rights Reserved. +================================================================= + + +To load all entities in this example consult the dynpred.loader +utility file (note that this is a Prolog file). + +This folder contains examples of using some of the built-in database +handling methods. diff --git a/Logtalk/examples/dynpred/SCRIPT b/Logtalk/examples/dynpred/SCRIPT new file mode 100644 index 000000000..fc2ccb875 --- /dev/null +++ b/Logtalk/examples/dynpred/SCRIPT @@ -0,0 +1,91 @@ +================================================================= +Logtalk - Object oriented extension to Prolog +Release 2.12.0 + +Copyright (c) 1998-2002 Paulo Moura. All Rights Reserved. +================================================================= + + +% Sending to descendant the message p/1, returns the definition in root: + +| ?- descendant::p(Value). + +Value = root +yes + + +% Asserting a local definition for p/1 in descendant overrides the inherited +% definition: + +| ?- descendant::(assertz(p(descendant)), p(Value)). + +Value = descendant +yes + + +% If we retract the local definition, again the inherited definition form root +% will be used: + +| ?- descendant::(retractall(p(_)), p(Value)). + +Value = root +yes + + +% class does not understand the message p1/1 (the predicate is declared only +% for the class descendant instances): + +| ?- class::p1(X). + +error(existence_error(predicate_declaration, p1(_)), class::p1(_), user) + + +% the same message is valid for the class instances: + +| ?- instance::p1(X). + +X = class +yes + + +% If we assert a clause for a new predicate, p2/1, in the class +% (a side-effect being a dynamic declaration of the predicate): + +| ?- class::assertz(p2(class)). + +yes + + +% the new predicate, like p1/1, is not available for the class: + +| ?- class::p2(Value). + +error(existence_error(predicate_declaration, p2(_)), class::p2(_), user) + + +% but is available for the class instances, the same way as p1/1: + +| ?- instance::p2(X). + +X = class +yes + + +% Using a prototype, assert three new predicates (the method object_assert/0 +% asserts the predicate public_predicate/0 from outside the prototype; the +% method self_assert/0 asserts the predicate protected_predicate/0 in self; +% the method this_assert/0 asserts the predicate private_predicate/0 in this): + +| ?- prototype::(object_assert, self_assert, this_assert). + +yes + + +% and check the resulting scope of each predicate: + +| ?- prototype::dynamic_predicates. + +public_predicate/0 - public +protected_predicate/0 - protected +private_predicate/0 - private +yes diff --git a/Logtalk/examples/dynpred/class.lgt b/Logtalk/examples/dynpred/class.lgt new file mode 100644 index 000000000..9089205ae --- /dev/null +++ b/Logtalk/examples/dynpred/class.lgt @@ -0,0 +1,12 @@ + +:- object(class, + instantiates(metaclass)). + + + :- public(p1/1). + + + p1(class). + + +:- end_object. diff --git a/Logtalk/examples/dynpred/descendant.lgt b/Logtalk/examples/dynpred/descendant.lgt new file mode 100644 index 000000000..1b7da37e0 --- /dev/null +++ b/Logtalk/examples/dynpred/descendant.lgt @@ -0,0 +1,6 @@ + +:- object(descendant, + extends(root)). + + +:- end_object. diff --git a/Logtalk/examples/dynpred/dynpred.loader b/Logtalk/examples/dynpred/dynpred.loader new file mode 100644 index 000000000..a2bee06db --- /dev/null +++ b/Logtalk/examples/dynpred/dynpred.loader @@ -0,0 +1,9 @@ + +:- initialization( + logtalk_load([ + root, + descendant, + metaclass, + class, + instance, + prototype])). diff --git a/Logtalk/examples/dynpred/instance.lgt b/Logtalk/examples/dynpred/instance.lgt new file mode 100644 index 000000000..ea9524000 --- /dev/null +++ b/Logtalk/examples/dynpred/instance.lgt @@ -0,0 +1 @@ + :- object(instance, instantiates(class)). :- end_object. \ No newline at end of file diff --git a/Logtalk/examples/dynpred/metaclass.lgt b/Logtalk/examples/dynpred/metaclass.lgt new file mode 100644 index 000000000..8c90b0276 --- /dev/null +++ b/Logtalk/examples/dynpred/metaclass.lgt @@ -0,0 +1,6 @@ + +:- object(metaclass, + instantiates(metaclass)). + + +:- end_object. diff --git a/Logtalk/examples/dynpred/prototype.lgt b/Logtalk/examples/dynpred/prototype.lgt new file mode 100644 index 000000000..6793e2ad1 --- /dev/null +++ b/Logtalk/examples/dynpred/prototype.lgt @@ -0,0 +1,42 @@ + +:- object(prototype). + + + :- public(object_assert/0). + :- public(self_assert/0). + :- public(this_assert/0). + + :- public(dynamic_predicates/0). + + + object_assert :- + self(Self), + Self::assertz(public_predicate). + + + self_assert :- + ::assertz(protected_predicate). + + + this_assert :- + assertz(private_predicate). + + + dynamic_predicates :- + current_predicate(Functor/Arity), + functor(Predicate, Functor, Arity), + predicate_property(Predicate, (dynamic)), + predicate_property(Predicate, Scope), + scope(Scope), + writeq(Functor/Arity), write(' - '), writeq(Scope), nl, + fail. + + dynamic_predicates. + + + scope(private). + scope(protected). + scope((public)). + + +:- end_object. diff --git a/Logtalk/examples/dynpred/root.lgt b/Logtalk/examples/dynpred/root.lgt new file mode 100644 index 000000000..6da324a1f --- /dev/null +++ b/Logtalk/examples/dynpred/root.lgt @@ -0,0 +1,12 @@ + +:- object(root). + + + :- public(p/1). + :- dynamic(p/1). + + + p(root). + + +:- end_object.