Logtalk 2.27.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1580 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
33
Logtalk/examples/proxies/NOTES
Normal file
33
Logtalk/examples/proxies/NOTES
Normal file
@@ -0,0 +1,33 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.27.1
|
||||
|
||||
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
||||
|
||||
To load this example and for sample queries, please see the SCRIPT file.
|
||||
|
||||
A parametric object may be used to represent objects whose "state" is static
|
||||
and set when the object is defined. However, there can be only one parametric
|
||||
object with a given functor and arity. For example, if we define the following
|
||||
parametric object:
|
||||
|
||||
:- object(circle(_Radius, _Color)).
|
||||
...
|
||||
:- end_object.
|
||||
|
||||
then the following terms may be interpreted as references to the object above:
|
||||
|
||||
circle(1, blue)
|
||||
circle(2, yellow)
|
||||
|
||||
In the context of parametric objects, the above terms are know as "parametric
|
||||
object proxies". Proxies represent different instantiations of a parametric
|
||||
object parameters. They may be stored on the database as Prolog facts. This
|
||||
results in a very compact representation, which can be an advantage when
|
||||
dealing with a large number of objects. However, this is also a fragile
|
||||
solution as changes on the parametric object ancestors may imply changes to
|
||||
the number and meaning of the parametric object parameters which, in turn,
|
||||
may imply changes to all the Prolog facts used to represent the individual
|
||||
objects.
|
24
Logtalk/examples/proxies/SCRIPT
Normal file
24
Logtalk/examples/proxies/SCRIPT
Normal file
@@ -0,0 +1,24 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.27.1
|
||||
|
||||
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
||||
|
||||
% start by loading the example:
|
||||
|
||||
| ?- logtalk_load(proxies(loader)).
|
||||
...
|
||||
|
||||
|
||||
% print the area and the perimeter for all circle proxies:
|
||||
|
||||
| ?- forall(circle(Id, R, C), (write(Id), write(' '), circle(R, C)::print)).
|
||||
|
||||
#1 area: 4.75291, perimeter: 7.72831, color: blue
|
||||
#2 area: 43.2412, perimeter: 23.3106, color: yellow
|
||||
#3 area: 0.477836, perimeter: 2.45044, color: green
|
||||
#4 area: 103.508, perimeter: 36.0655, color: black
|
||||
#5 area: 217.468, perimeter: 52.2761, color: cyan
|
||||
yes
|
13
Logtalk/examples/proxies/loader.lgt
Normal file
13
Logtalk/examples/proxies/loader.lgt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load(
|
||||
[proxies])).
|
||||
|
||||
/*
|
||||
If you intend to use the FOP XSL:FO processor for generating PDF documenting
|
||||
files, comment the directive above and uncomment the directive below
|
||||
|
||||
:- initialization(
|
||||
logtalk_load(
|
||||
[proxies], [xmlsref(standalone)])).
|
||||
*/
|
39
Logtalk/examples/proxies/proxies.lgt
Normal file
39
Logtalk/examples/proxies/proxies.lgt
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
:- object(circle(_Radius, _Color)).
|
||||
|
||||
:- public([
|
||||
radius/1,
|
||||
color/1,
|
||||
area/1,
|
||||
perimeter/1,
|
||||
print/0]).
|
||||
|
||||
radius(Radius) :-
|
||||
parameter(1, Radius).
|
||||
|
||||
color(Color) :-
|
||||
parameter(2, Color).
|
||||
|
||||
area(Area) :-
|
||||
::radius(Radius),
|
||||
Area is 3.1415927*Radius*Radius.
|
||||
|
||||
perimeter(Perimeter) :-
|
||||
::radius(Radius),
|
||||
Perimeter is 2*3.1415927*Radius.
|
||||
|
||||
print :-
|
||||
area(Area), write('area: '), write(Area),
|
||||
perimeter(Perimeter), write(', perimeter: '), write(Perimeter),
|
||||
color(Color), write(', color: '), write(Color), nl.
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
% parametric object proxies (with an extra argument to represent identity):
|
||||
|
||||
circle('#1', 1.23, blue).
|
||||
circle('#2', 3.71, yellow).
|
||||
circle('#3', 0.39, green).
|
||||
circle('#4', 5.74, black).
|
||||
circle('#5', 8.32, cyan).
|
Reference in New Issue
Block a user