| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The Perl Foundation. Consult the "LICENSE.txt" file for details. |
|---|
| 9 | ================================================================ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | % start by loading the example and the required library files: |
|---|
| 13 | |
|---|
| 14 | | ?- logtalk_load(polygons(loader)). |
|---|
| 15 | ... |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | % first create four polygons and move each one to a different position |
|---|
| 19 | |
|---|
| 20 | | ?- triangle::new(t, [position-(4, 5)]). |
|---|
| 21 | yes |
|---|
| 22 | |
|---|
| 23 | | ?- square::new(s, [position-(3, 2)]). |
|---|
| 24 | yes |
|---|
| 25 | |
|---|
| 26 | | ?- pentagon::new(p, [position-(7, 1)]). |
|---|
| 27 | yes |
|---|
| 28 | |
|---|
| 29 | | ?- hexagon::new(h, [position-(2, 4)]). |
|---|
| 30 | yes |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | % create two tuples of relation concentric |
|---|
| 34 | |
|---|
| 35 | | ?- concentric::add_tuple([t, s]). |
|---|
| 36 | yes |
|---|
| 37 | |
|---|
| 38 | | ?- concentric::add_tuple([p, h]). |
|---|
| 39 | yes |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | % check results |
|---|
| 43 | |
|---|
| 44 | | ?- concentric::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 45 | [t,s] |
|---|
| 46 | [p,h] |
|---|
| 47 | no |
|---|
| 48 | |
|---|
| 49 | | ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh). |
|---|
| 50 | Xh = 7, |
|---|
| 51 | Yh = 1, |
|---|
| 52 | Xp = 7, |
|---|
| 53 | Xs = 4, |
|---|
| 54 | Xt = 4, |
|---|
| 55 | Yp = 1, |
|---|
| 56 | Ys = 5, |
|---|
| 57 | Yt = 5 |
|---|
| 58 | yes |
|---|
| 59 | |
|---|
| 60 | | ?- after_event_registry::monitors(Ma). |
|---|
| 61 | Ma = [concentric] |
|---|
| 62 | yes |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | % move the triangle and the hexagon to new positions |
|---|
| 66 | |
|---|
| 67 | | ?- t::move(3, 3), h::move(8, 4). |
|---|
| 68 | yes |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | % check results |
|---|
| 72 | |
|---|
| 73 | | ?- concentric::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 74 | [t,s] |
|---|
| 75 | [p,h] |
|---|
| 76 | no |
|---|
| 77 | |
|---|
| 78 | | ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh). |
|---|
| 79 | Xh = 8, |
|---|
| 80 | Yh = 4, |
|---|
| 81 | Xp = 8, |
|---|
| 82 | Xs = 3, |
|---|
| 83 | Xt = 3, |
|---|
| 84 | Yp = 4, |
|---|
| 85 | Ys = 3, |
|---|
| 86 | Yt = 3 |
|---|
| 87 | yes |
|---|
| 88 | |
|---|
| 89 | | ?- after_event_registry::monitors(Ma). |
|---|
| 90 | Ma = [concentric] |
|---|
| 91 | yes |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | % create another tuple of relation concentric |
|---|
| 95 | |
|---|
| 96 | | ?- concentric::add_tuple([t, p]). |
|---|
| 97 | yes |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | % move the pentagon to a new position |
|---|
| 101 | |
|---|
| 102 | | ?- p::move(2, 7). |
|---|
| 103 | yes |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | % check results |
|---|
| 107 | |
|---|
| 108 | | ?- concentric::tuple(Tuple), write(Tuple), nl, fail. |
|---|
| 109 | [t,s] |
|---|
| 110 | [p,h] |
|---|
| 111 | [t,p] |
|---|
| 112 | no |
|---|
| 113 | |
|---|
| 114 | | ?- t::position(Xt, Yt), s::position(Xs, Ys), p::position(Xp, Yp), h::position(Xh, Yh). |
|---|
| 115 | Xh = 2, |
|---|
| 116 | Yh = 7, |
|---|
| 117 | Xp = 2, |
|---|
| 118 | Xs = 2, |
|---|
| 119 | Xt = 2, |
|---|
| 120 | Yp = 7, |
|---|
| 121 | Ys = 7, |
|---|
| 122 | Yt = 7 |
|---|
| 123 | yes |
|---|
| 124 | |
|---|
| 125 | | ?- after_event_registry::monitors(Monitors). |
|---|
| 126 | Monitors = [concentric] |
|---|
| 127 | yes |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | % clean up instances, tuples and monitors |
|---|
| 131 | |
|---|
| 132 | | ?- concentric::remove_all_tuples. |
|---|
| 133 | yes |
|---|
| 134 | |
|---|
| 135 | | ?- triangle::delete(t). |
|---|
| 136 | yes |
|---|
| 137 | |
|---|
| 138 | | ?- square::delete(s). |
|---|
| 139 | yes |
|---|
| 140 | |
|---|
| 141 | | ?- pentagon::delete(p). |
|---|
| 142 | yes |
|---|
| 143 | |
|---|
| 144 | | ?- hexagon::delete(h). |
|---|
| 145 | yes |
|---|