2001-06-06 20:40:57 +01:00
|
|
|
=================================================================
|
|
|
|
Logtalk - Object oriented extension to Prolog
|
2006-03-26 18:31:34 +01:00
|
|
|
Release 2.27.1
|
2001-06-06 20:40:57 +01:00
|
|
|
|
2006-02-10 17:44:05 +00:00
|
|
|
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
2001-06-06 20:40:57 +01:00
|
|
|
=================================================================
|
|
|
|
|
|
|
|
|
2004-11-29 20:36:31 +00:00
|
|
|
% start by loading the necessary library support files (if not
|
|
|
|
% already loaded):
|
2004-06-13 19:04:28 +01:00
|
|
|
|
2004-11-29 20:36:31 +00:00
|
|
|
| ?- logtalk_load([library(hierarchies_loader), library(types_loader)]).
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
% now you are ready for loading the example:
|
|
|
|
|
|
|
|
| ?- logtalk_load(sicstus(loader)).
|
2004-06-13 19:04:28 +01:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
% try some simple queries:
|
|
|
|
|
|
|
|
|
2001-06-06 20:40:57 +01:00
|
|
|
| ?- sort(rational)::sort([1/8, 2/7, 6/5, 2/9, 1/3], Sorted).
|
|
|
|
|
|
|
|
Sorted = [1/8, 2/9, 2/7, 1/3, 6/5]
|
2001-12-05 23:57:48 +00:00
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
| ?- sort(colours)::sort([orange, indigo, red, yellow, violet, blue, green], Sorted).
|
|
|
|
|
|
|
|
Sorted = [red, orange, yellow, green, blue, indigo, violet]
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% using the pseudo-object user implies using the Prolog built-in standard
|
|
|
|
% order operators:
|
|
|
|
|
2001-06-06 20:40:57 +01:00
|
|
|
| ?- sort(user)::sort([3, 1, 4, 2, 9], Sorted).
|
|
|
|
|
|
|
|
Sorted = [1, 2, 3, 4, 9]
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% some messages testing object parameter passing and using:
|
|
|
|
|
2001-06-06 20:40:57 +01:00
|
|
|
| ?- red_circle(3)::color(Color).
|
|
|
|
|
|
|
|
Color = red
|
2001-12-05 23:57:48 +00:00
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
| ?- red_circle(3)::area(Area).
|
|
|
|
|
|
|
|
Area = 28.274334
|
2001-12-05 23:57:48 +00:00
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
| ?- red_circle(3)::ancestors(As).
|
|
|
|
|
|
|
|
As = [circle(3, red), ellipse(3, 3, red)]
|
2001-12-05 23:57:48 +00:00
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% show the execution context using a method (context/3) that is defined in the
|
|
|
|
% hierarchy root and specialized (using super calls) in each descendant:
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
| ?- red_circle(3)::context.
|
|
|
|
|
|
|
|
red_circle1
|
|
|
|
self: red_circle(3)
|
|
|
|
this: red_circle(3)
|
|
|
|
sender: user
|
|
|
|
|
|
|
|
circle2
|
|
|
|
self: red_circle(3)
|
|
|
|
this: circle(3,red)
|
|
|
|
sender: user
|
|
|
|
|
|
|
|
ellipse3
|
|
|
|
self: red_circle(3)
|
|
|
|
this: ellipse(3,3,red)
|
|
|
|
sender: user
|
|
|
|
|
|
|
|
yes
|
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% send a conjunction of messages/goals to an object; just some useful syntax
|
|
|
|
% sugar:
|
|
|
|
|
2001-06-06 20:40:57 +01:00
|
|
|
| ?- square(2)::(side(Side), width(Width), height(Height), area(Area)).
|
|
|
|
|
|
|
|
Side = 2
|
|
|
|
Width = 2
|
|
|
|
Height = 2
|
|
|
|
Area = 4
|
2001-12-05 23:57:48 +00:00
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% find all messages accepted by an object:
|
|
|
|
|
2001-06-06 20:40:57 +01:00
|
|
|
| ?- square(2)::current_predicate(Pred).
|
|
|
|
|
|
|
|
Pred = side/1 ;
|
|
|
|
Pred = width/1 ;
|
|
|
|
Pred = height/1 ;
|
2005-12-24 18:00:21 +00:00
|
|
|
Pred = area/1
|
|
|
|
yes
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
% find all data on a specific message accepted by an object:
|
2001-06-06 20:40:57 +01:00
|
|
|
|
|
|
|
| ?- square(_)::predicate_property(side(_), Prop).
|
|
|
|
|
|
|
|
Prop = public ;
|
|
|
|
Prop = static ;
|
|
|
|
Prop = declared_in(square(_133)) ;
|
2005-12-24 18:00:21 +00:00
|
|
|
Prop = defined_in(square(_164))
|
|
|
|
yes
|