Logtalk 2.25.0 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1288 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.24.0
|
||||
Release 2.25.0
|
||||
|
||||
Copyright (c) 1998-2005 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
@@ -10,4 +10,4 @@ To load this example and for sample queries, please see the SCRIPT
|
||||
file.
|
||||
|
||||
For a description of this example, please see the comments in the
|
||||
aliases.mlgt metafile.
|
||||
aliases.lgt source file.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.24.0
|
||||
Release 2.25.0
|
||||
|
||||
Copyright (c) 1998-2005 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
@@ -30,6 +30,23 @@ yes
|
||||
Side = 2
|
||||
yes
|
||||
|
||||
| ?- square(2)::predicate_property(side(_), Property).
|
||||
|
||||
Property = public ;
|
||||
Property = static ;
|
||||
Property = declared_in(rectangle(_G264, _G265)) ;
|
||||
Property = defined_in(rectangle(_G297, _G298)) ;
|
||||
Property = alias(width(_G182))
|
||||
yes
|
||||
|
||||
| ?- square(2)::predicate_property(width(_), Property).
|
||||
|
||||
Property = public ;
|
||||
Property = static ;
|
||||
Property = declared_in(rectangle(_G262, _G263)) ;
|
||||
Property = defined_in(rectangle(_G293, _G294))
|
||||
yes
|
||||
|
||||
|
||||
% check the object circle(_) public protocol:
|
||||
|
||||
|
70
Logtalk/examples/aliases/aliases.lgt
Normal file
70
Logtalk/examples/aliases/aliases.lgt
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
This example illustrates the use of the predicate directive alias/3 for
|
||||
defining alternative names for inherited predicates.
|
||||
*/
|
||||
|
||||
|
||||
% first, we define a simple parametric object for representing rectangles:
|
||||
|
||||
:- object(rectangle(_Width, _Height)).
|
||||
|
||||
:- public(width/1).
|
||||
:- public(height/1).
|
||||
:- public(area/1).
|
||||
|
||||
width(Width) :-
|
||||
parameter(1, Width).
|
||||
|
||||
height(Height) :-
|
||||
parameter(2, Height).
|
||||
|
||||
area(Area) :-
|
||||
::width(Width),
|
||||
::height(Height),
|
||||
Area is Width*Height.
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
% next, we define a square object which adds an alias, side/1, for the
|
||||
% inherited predicate width/1:
|
||||
|
||||
:- object(square(Side),
|
||||
extends(rectangle(Side, Side))).
|
||||
|
||||
:- alias(rectangle(_, _), width/1, side/1).
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
% a similar example can be defined using ellipses and circles:
|
||||
|
||||
:- object(ellipse(_RX, _RY)).
|
||||
|
||||
:- public(rx/1).
|
||||
:- public(ry/1).
|
||||
:- public(area/1).
|
||||
|
||||
rx(Rx) :-
|
||||
parameter(1, Rx).
|
||||
|
||||
ry(Ry) :-
|
||||
parameter(2, Ry).
|
||||
|
||||
area(Area) :-
|
||||
::rx(Rx),
|
||||
::ry(Ry),
|
||||
Area is Rx*Ry*3.1415927.
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
||||
% in this case, we define an alias named r/1 for the inherited
|
||||
% predicate rx/1:
|
||||
|
||||
:- object(circle(Radius),
|
||||
extends(ellipse(Radius, Radius))).
|
||||
|
||||
:- alias(ellipse(_, _), rx/1, r/1).
|
||||
|
||||
:- end_object.
|
Reference in New Issue
Block a user