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,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 classvars.loader utility
file (note that the *.loader files are Prolog files).
This folder contains an example that shows how to implement class variables
as defined in Smalltalk. The name shared instance variables is however much
more accurate. In systems like Logtalk that enable the use of explicit
metaclasses, true class variables are just the class (as an object) own
instance variables!

View File

@@ -0,0 +1,32 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% get the value of the class variable for each instance:
| ?- instance1::cv(Value1), instance2::cv(Value2), instance3::cv(Value3).
Value1 = 0
Value2 = 0
Value3 = 0
yes
% change the value of the class variable via instance1:
| ?- instance1::set_cv(1).
yes
% get the value of the class variable for the other instances:
| ?- instance2::cv(Value2), instance3::cv(Value3).
Value2 = 1
Value3 = 1
yes

View File

@@ -0,0 +1,7 @@
:- initialization(
logtalk_load([
root,
instance1,
instance2,
instance3])).

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,29 @@
:- object(root,
instantiates(root)).
:- private(cv_/1).
:- dynamic(cv_/1).
:- mode(cv_(?integer), zero_or_one).
:- public(cv/1).
:- mode(cv(?integer), zero_or_one).
:- public(set_cv/1).
:- mode(set_cv(+integer), one).
cv_(0). % cv value is stored locally, in this class
cv(Value) :-
cv_(Value). % retrive cv value, shared for all instances
set_cv(Value) :-
retractall(cv_(_)), % retract old cv value from this class
asserta(cv_(Value)). % assert the new value in this class
:- end_object.