|
Revision 4601, 1.2 KB
(checked in by pmoura, 7 weeks ago)
|
|
Added svn:mime-type property to source files (set to text/x-logtalk).
|
-
Property svn:mime-type set to
text/x-logtalk
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | |
|---|
| 2 | :- object(rectangle(_Width, _Height, _Position), |
|---|
| 3 | imports(private::assignvars)). |
|---|
| 4 | |
|---|
| 5 | :- info([ |
|---|
| 6 | version is 1.0, |
|---|
| 7 | author is 'Paulo Moura', |
|---|
| 8 | date is 2005/1/8, |
|---|
| 9 | comment is 'A simple implementation of a geometric rectangle using assignable variables and parametric objects.', |
|---|
| 10 | parnames is ['Width', 'Height', 'Position']]). |
|---|
| 11 | |
|---|
| 12 | :- public(init/0). |
|---|
| 13 | :- mode(init, one). |
|---|
| 14 | :- info(init/0, |
|---|
| 15 | [comment is 'Initialize rectangle position.']). |
|---|
| 16 | |
|---|
| 17 | :- public(area/1). |
|---|
| 18 | :- mode(area(-integer), one). |
|---|
| 19 | :- info(area/1, |
|---|
| 20 | [comment is 'Rectangle area.', |
|---|
| 21 | argnames is ['Area']]). |
|---|
| 22 | |
|---|
| 23 | :- public(move/2). |
|---|
| 24 | :- mode(move(+integer, +integer), one). |
|---|
| 25 | :- info(move/2, [ |
|---|
| 26 | comment is 'Moves a rectangle to a new position.', |
|---|
| 27 | argnames is ['X', 'Y']]). |
|---|
| 28 | |
|---|
| 29 | :- public(position/2). |
|---|
| 30 | :- mode(position(?integer, ?integer), zero_or_one). |
|---|
| 31 | :- info(position/2, [ |
|---|
| 32 | comment is 'Rectangle current position.', |
|---|
| 33 | argnames is ['X', 'Y']]). |
|---|
| 34 | |
|---|
| 35 | init :- |
|---|
| 36 | parameter(3, Position), |
|---|
| 37 | ::assignable(Position, (0, 0)). |
|---|
| 38 | |
|---|
| 39 | area(Area) :- |
|---|
| 40 | parameter(1, Width), |
|---|
| 41 | parameter(2, Height), |
|---|
| 42 | Area is Width*Height. |
|---|
| 43 | |
|---|
| 44 | move(X, Y) :- |
|---|
| 45 | parameter(3, Position), |
|---|
| 46 | ::Position <= (X, Y). |
|---|
| 47 | |
|---|
| 48 | position(X, Y) :- |
|---|
| 49 | parameter(3, Position), |
|---|
| 50 | ::Position => (X, Y). |
|---|
| 51 | |
|---|
| 52 | :- end_object. |
|---|