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:
14
Logtalk/examples/instmethods/NOTES
Normal file
14
Logtalk/examples/instmethods/NOTES
Normal file
@@ -0,0 +1,14 @@
|
||||
=================================================================
|
||||
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 instmethods.loader utility
|
||||
file (note that the *.loader files are Prolog files).
|
||||
|
||||
This folder contains an example of instance defined methods. When using
|
||||
classes and instances, methods must be declared in a class but the method
|
||||
definitions may be stored in the instances, either overriding or specializing
|
||||
the class definitions.
|
36
Logtalk/examples/instmethods/SCRIPT
Normal file
36
Logtalk/examples/instmethods/SCRIPT
Normal file
@@ -0,0 +1,36 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.8.4
|
||||
|
||||
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
||||
|
||||
% instance1 definition for method "method" is found in its class:
|
||||
|
||||
| ?- instance1::method.
|
||||
|
||||
This is the default definition for the method, stored in class root.
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% instance2 overrides definition of method "method"
|
||||
|
||||
| ?- instance2::method.
|
||||
|
||||
This is an overriding definition stored in the instance2 instance itself.
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% instance3 specializes definition of method "method"
|
||||
|
||||
| ?- instance3::method.
|
||||
|
||||
This is a specializing definition stored in the instance3 instance itself.
|
||||
It makes a super call to execute the default definition:
|
||||
|
||||
This is the default definition for the method, stored in class root.
|
||||
|
||||
yes
|
6
Logtalk/examples/instmethods/instance1.lgt
Normal file
6
Logtalk/examples/instmethods/instance1.lgt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
:- object(instance1,
|
||||
instantiates(root)).
|
||||
|
||||
|
||||
:- end_object.
|
13
Logtalk/examples/instmethods/instance2.lgt
Normal file
13
Logtalk/examples/instmethods/instance2.lgt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
:- object(instance2,
|
||||
instantiates(root)).
|
||||
|
||||
|
||||
method :-
|
||||
this(This),
|
||||
write('This is an overriding definition stored in the '),
|
||||
writeq(This),
|
||||
write(' instance itself.'), nl.
|
||||
|
||||
|
||||
:- end_object.
|
15
Logtalk/examples/instmethods/instance3.lgt
Normal file
15
Logtalk/examples/instmethods/instance3.lgt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
:- object(instance3,
|
||||
instantiates(root)).
|
||||
|
||||
|
||||
method :-
|
||||
this(This),
|
||||
write('This is a specializing definition stored in the '),
|
||||
writeq(This),
|
||||
write(' instance itself.'), nl,
|
||||
write('It makes a super call to execute the default definition:'), nl, nl,
|
||||
^^method.
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/instmethods/instmethods.loader
Normal file
7
Logtalk/examples/instmethods/instmethods.loader
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([
|
||||
root,
|
||||
instance1,
|
||||
instance2,
|
||||
instance3])).
|
15
Logtalk/examples/instmethods/root.lgt
Normal file
15
Logtalk/examples/instmethods/root.lgt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
:- object(root,
|
||||
instantiates(root)).
|
||||
|
||||
|
||||
:- public(method/0).
|
||||
|
||||
|
||||
method :-
|
||||
this(This),
|
||||
write('This is the default definition for the method, stored in class '),
|
||||
writeq(This), write('.'), nl.
|
||||
|
||||
|
||||
:- end_object.
|
Reference in New Issue
Block a user