|
Revision 4601, 1.5 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(object, |
|---|
| 3 | imports(category)). |
|---|
| 4 | |
|---|
| 5 | :- info([ |
|---|
| 6 | version is 3.0, |
|---|
| 7 | author is 'Paulo Moura', |
|---|
| 8 | date is 2007/06/11, |
|---|
| 9 | comment is 'Example object for benchmarking library predicate calls and imported category predicate calls.']). |
|---|
| 10 | |
|---|
| 11 | :- public(length/2). |
|---|
| 12 | |
|---|
| 13 | length(List, Length) :- |
|---|
| 14 | length(List, 0, Length). |
|---|
| 15 | |
|---|
| 16 | length([], Length, Length). |
|---|
| 17 | length([_| Tail], Acc, Length) :- |
|---|
| 18 | Acc2 is Acc + 1, |
|---|
| 19 | length(Tail, Acc2, Length). |
|---|
| 20 | |
|---|
| 21 | :- public(ctg_self/0). |
|---|
| 22 | % call an imported category predicate by sending a message to self; |
|---|
| 23 | % performance will depend on the distance between "self" and "this" |
|---|
| 24 | % (always uses dynamic binding) |
|---|
| 25 | ctg_self :- |
|---|
| 26 | ::ctg_pred. |
|---|
| 27 | |
|---|
| 28 | :- public(ctg_direct/0). |
|---|
| 29 | % call an imported category predicate directly by using the :/1 control construct; |
|---|
| 30 | % (static binding may be used, depending on how the category is compiled) |
|---|
| 31 | ctg_direct :- |
|---|
| 32 | :ctg_pred. |
|---|
| 33 | |
|---|
| 34 | :- public(obj_local/0). |
|---|
| 35 | % call a local object predicate directly; used for comparing performance with |
|---|
| 36 | % calls to category predicates using the ::/1 and :/1 control constructs |
|---|
| 37 | obj_local :- |
|---|
| 38 | {generate_list(20, List)}, |
|---|
| 39 | length(List, _). |
|---|
| 40 | |
|---|
| 41 | :- end_object. |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | :- object(descendant, |
|---|
| 45 | extends(object)). |
|---|
| 46 | |
|---|
| 47 | :- info([ |
|---|
| 48 | version is 1.0, |
|---|
| 49 | author is 'Paulo Moura', |
|---|
| 50 | date is 2007/04/17, |
|---|
| 51 | comment is 'Example object used for simulating a small hierarchy.']). |
|---|
| 52 | |
|---|
| 53 | :- end_object. |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | :- object(leaf, |
|---|
| 57 | extends(descendant)). |
|---|
| 58 | |
|---|
| 59 | :- info([ |
|---|
| 60 | version is 1.0, |
|---|
| 61 | author is 'Paulo Moura', |
|---|
| 62 | date is 2007/04/17, |
|---|
| 63 | comment is 'Example object used for simulating a small hierarchy.']). |
|---|
| 64 | |
|---|
| 65 | :- end_object. |
|---|