Logtalk 2.26.2 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1487 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura
2005-12-24 18:07:41 +00:00
parent 9f1b358c04
commit 3455276aa2
55 changed files with 6535 additions and 0 deletions

View File

@@ -0,0 +1,169 @@
:- object(math_constants).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Implements predicates for retriving common mathematical constants.']).
:- public(pi/1).
:- mode(pi(-float), one).
:- public(e/1).
:- mode(e(-float), one).
pi(Pi) :-
Pi is 4.0*atan(1.0).
e(E) :-
E is exp(1.0).
:- end_object.
:- object(ellipse(_RX, _RY, _Color),
imports(proto_hierarchy)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric ellipses.',
parnames is ['RX', 'RY', 'Color'],
source is 'Example adopted from the SICStus Objects documentation.']).
:- uses(math_constants).
:- public(color/1).
:- mode(color(?atom), zero_or_one).
:- info(color/1, [
comment is 'Ellipse color.',
argnames is ['Color']]).
:- public(rx/1).
:- mode(rx(?number), zero_or_one).
:- info(rx/1, [
comment is 'Ellipse x axis.',
argnames is ['Rx']]).
:- public(ry/1).
:- mode(ry(?number), zero_or_one).
:- info(ry/1, [
comment is 'Ellipse y axis.',
argnames is ['Ry']]).
:- public(area/1).
:- mode(area(-number), one).
:- info(area/1, [
comment is 'Ellipse area.',
argnames is ['Area']]).
:- public(context/0).
:- mode(context, one).
:- info(context/0, [
comment is 'Shows execution context (self, this and sender values).']).
color(Color) :-
parameter(3, Color).
rx(Rx) :-
parameter(1, Rx).
ry(Ry) :-
parameter(2, Ry).
area(Area) :-
::rx(Rx),
::ry(Ry),
math_constants::pi(Pi),
Area is Rx*Ry*Pi.
context :-
write(ellipse3), nl,
self(Self), write('self: '), writeq(Self), nl,
this(This), write('this: '), writeq(This), nl,
sender(Sender), write('sender: '), writeq(Sender), nl, nl.
:- end_object.
:- object(circle(Radius, Color),
extends(ellipse(Radius, Radius, Color))).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric circles.',
parnames is ['Radius', 'Color'],
source is 'Example adopted from the SICStus Objects documentation.']).
:- public(r/1).
:- mode(r(?number), zero_or_one).
:- info(r/1, [
comment is 'Circle radius.',
argnames is ['Radius']]).
r(Radius) :-
parameter(1, Radius).
color(Color) :-
parameter(2, Color).
rx(Radius) :-
::r(Radius).
ry(Radius) :-
::r(Radius).
context :-
write(circle2), nl,
self(Self), write('self: '), writeq(Self), nl,
this(This), write('this: '), writeq(This), nl,
sender(Sender), write('sender: '), writeq(Sender), nl, nl,
^^context.
:- end_object.
:- object(circle1(Color),
extends(circle(1, Color))).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric circles with radius = 1.',
parnames is ['Color'],
source is 'Example adopted from the SICStus Objects documentation.']).
context :-
write(circle11), nl,
self(Self), write('self: '), writeq(Self), nl,
this(This), write('this: '), writeq(This), nl,
sender(Sender), write('sender: '), writeq(Sender), nl,
^^context.
:- end_object.
:- object(red_circle(Radius),
extends(circle(Radius, red))).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric red circles.',
parnames is ['Radius'],
source is 'Example adopted from the SICStus Objects documentation.']).
context :-
write(red_circle1), nl,
self(Self), write('self: '), writeq(Self), nl,
this(This), write('this: '), writeq(This), nl,
sender(Sender), write('sender: '), writeq(Sender), nl, nl,
^^context.
:- end_object.

View File

@@ -0,0 +1,68 @@
:- object(rectangle(_Width, _Height)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric rectangles.',
parnames is ['Width', 'Height']]).
:- public(width/1).
:- mode(width(?number), zero_or_one).
:- info(width/1, [
comment is 'Rectangle width.',
argnames is ['Width']]).
:- public(height/1).
:- mode(height(?number), zero_or_one).
:- info(height/1, [
comment is 'Rectangle height.',
argnames is ['Height']]).
:- public(area/1).
:- mode(area(-number), one).
:- info(area/1, [
comment is 'Rectangle area.',
argnames is ['Area']]).
width(Width) :-
parameter(1, Width).
height(Height) :-
parameter(2, Height).
area(Area) :-
::width(Width),
::height(Height),
Area is Width*Height.
:- end_object.
:- object(square(Side),
extends(rectangle(Side, Side))).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Parametric object for representing geometric squares.',
parnames is ['Side']]).
:- public(side/1).
:- mode(side(?number), zero_or_one).
:- info(side/1, [
comment is 'Square side.',
argnames is ['Side']]).
side(Side) :-
parameter(1, Side).
width(Width) :-
parameter(1, Width).
height(Height) :-
parameter(1, Height).
:- end_object.

View File

@@ -0,0 +1,119 @@
:- object(sort(_Type)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'List sorting parameterized by the type of the list elements.',
parnames is ['Type'],
source is 'Example adopted from the SICStus Objects documentation.']).
:- uses(list).
:- calls(comparingp).
:- public(sort/2).
:- mode(sort(+list, -list), one).
:- info(sort/2, [
comment is 'Sorts a list in ascending order.',
argnames is ['List', 'Sorted']]).
:- private(partition/4).
:- mode(partition(+list, +nonvar, -list, -list), one).
:- info(partition/4, [
comment is 'List partition in two sub-lists using a pivot.',
argnames is ['List', 'Pivot', 'Lowers', 'Biggers']]).
sort([], []).
sort([P| L], S) :-
partition(L, P, Small, Large),
sort(Small, S0),
sort(Large, S1),
list::append(S0, [P| S1], S).
partition([], _, [], []).
partition([X| L1], P, Small, Large) :-
parameter(1, Type),
( Type::(X < P) ->
Small = [X| Small1], Large = Large1
; Small = Small1, Large = [X| Large1]
),
partition(L1, P, Small1, Large1).
:- end_object.
:- object(rational,
implements(comparingp)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Implements comparison between rational numbers represented as Num/Den.']).
N1/D1 < N2/D2 :-
{N1*D2 < N2*D1}.
N1/D1 =< N2/D2 :-
{N1*D2 =< N2*D1}.
N1/D1 > N2/D2 :-
{N1*D2 > N2*D1}.
N1/D1 >= N2/D2 :-
{N1*D2 >= N2*D1}.
N1/D1 =:= N2/D2 :-
{N1*D2 =:= N2*D1}.
N1/D1 =\= N2/D2 :-
{N1*D2 =\= N2*D1}.
:- end_object.
:- object(colours,
implements(comparingp)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Implements comparison between visible colors.']).
Colour1 < Colour2 :-
order(Colour1, N1),
order(Colour2, N2),
{N1 < N2}.
Colour1 =< Colour2 :-
order(Colour1, N1),
order(Colour2, N2),
{N1 =< N2}.
Colour1 > Colour2 :-
order(Colour1, N1),
order(Colour2, N2),
{N1 > N2}.
Colour1 >= Colour2 :-
order(Colour1, N1),
order(Colour2, N2),
{N1 >= N2}.
Colour1 =:= Colour2 :-
{Colour1 == Colour2}.
Colour1 =\= Colour2 :-
{Colour1 \== Colour2}.
order(red, 1).
order(orange, 2).
order(yellow, 3).
order(green, 4).
order(blue, 5).
order(indigo, 6).
order(violet, 7).
:- end_object.