|
Revision 4601, 2.0 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 | % general information about Joe: |
|---|
| 3 | |
|---|
| 4 | :- object(joePerson). |
|---|
| 5 | |
|---|
| 6 | :- public(getOlder/0). |
|---|
| 7 | |
|---|
| 8 | :- public(address/1). |
|---|
| 9 | |
|---|
| 10 | :- public(age/1). |
|---|
| 11 | :- dynamic(age/1). |
|---|
| 12 | |
|---|
| 13 | :- public(name/1). |
|---|
| 14 | |
|---|
| 15 | :- public(phone/1). |
|---|
| 16 | |
|---|
| 17 | :- public(score/1). |
|---|
| 18 | :- dynamic(score/1). |
|---|
| 19 | |
|---|
| 20 | :- public(setScore/1). |
|---|
| 21 | |
|---|
| 22 | getOlder :- % this predicate uses property sharing, i.e. |
|---|
| 23 | retract(age(Old)), % the property and its value are shared by all |
|---|
| 24 | New is Old + 1, % descendant prototypes/viewpoints; changes |
|---|
| 25 | asserta(age(New)). % are shared no matter which viewpoint receives |
|---|
| 26 | % the getOlder/1 message |
|---|
| 27 | address('8 Octave Street'). |
|---|
| 28 | |
|---|
| 29 | age(30). |
|---|
| 30 | |
|---|
| 31 | name('John'). |
|---|
| 32 | |
|---|
| 33 | phone(11-11-11-11). |
|---|
| 34 | |
|---|
| 35 | score(0). % default value for the score/1 property, |
|---|
| 36 | % shared by all descendant prototypes/viewpoints; |
|---|
| 37 | setScore(Score) :- % changing the default value results in |
|---|
| 38 | ::retractall(score(_)), % in a local value stored in the descendant |
|---|
| 39 | ::asserta(score(Score)). % prototype that received the setScore/1 message |
|---|
| 40 | |
|---|
| 41 | :- end_object. |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | % information on Joe as an employee: |
|---|
| 45 | |
|---|
| 46 | :- object(joeEmployee, |
|---|
| 47 | extends(joePerson)). |
|---|
| 48 | |
|---|
| 49 | :- public(worksFor/1). |
|---|
| 50 | |
|---|
| 51 | :- public(salary/1). |
|---|
| 52 | :- dynamic(salary/1). |
|---|
| 53 | |
|---|
| 54 | :- public(giveRaise/1). |
|---|
| 55 | |
|---|
| 56 | worksFor('ToonTown'). |
|---|
| 57 | |
|---|
| 58 | salary(1500). |
|---|
| 59 | |
|---|
| 60 | giveRaise(Raise) :- % another example of property sharing |
|---|
| 61 | retract(salary(Old)), |
|---|
| 62 | New is Old + Raise, |
|---|
| 63 | asserta(salary(New)). |
|---|
| 64 | |
|---|
| 65 | :- end_object. |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | % information on Joe as an chess player: |
|---|
| 69 | |
|---|
| 70 | :- object(joeChessPlayer, |
|---|
| 71 | extends(joePerson)). |
|---|
| 72 | |
|---|
| 73 | :- public(category/1). |
|---|
| 74 | |
|---|
| 75 | category('National Master'). |
|---|
| 76 | |
|---|
| 77 | :- end_object. |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | % information on Joe as a movies fan: |
|---|
| 81 | |
|---|
| 82 | :- object(joeFilmEnthusiast, |
|---|
| 83 | extends(joePerson)). |
|---|
| 84 | |
|---|
| 85 | :- public(favActor/1). |
|---|
| 86 | :- public(favFilm/1). |
|---|
| 87 | :- public(favDirector/1). |
|---|
| 88 | |
|---|
| 89 | favActor('Fred Filistone'). |
|---|
| 90 | |
|---|
| 91 | favFilm('The Wizard of Oz'). |
|---|
| 92 | |
|---|
| 93 | favDirector('Krzystof Kieslowski'). |
|---|
| 94 | |
|---|
| 95 | :- end_object. |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | % information on Joe as a sportsman: |
|---|
| 99 | |
|---|
| 100 | :- object(joeSportsman, |
|---|
| 101 | extends(joePerson)). |
|---|
| 102 | |
|---|
| 103 | :- public(sport/1). |
|---|
| 104 | :- public(stamina/1). |
|---|
| 105 | :- public(weight/1). |
|---|
| 106 | |
|---|
| 107 | sport(snowboard). |
|---|
| 108 | |
|---|
| 109 | stamina(30). |
|---|
| 110 | |
|---|
| 111 | weight(111). |
|---|
| 112 | |
|---|
| 113 | :- end_object. |
|---|