root/trunk/examples/complements/complements.lgt

Revision 4601, 0.9 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
Line 
1
2% setup the object employee as a monitor for any message sent to itself:
3:- initialization(define_events(before, employee, _, _, employee)).
4
5
6:- object(employee).
7
8    :- public([name/1, age/1, salary/1]).
9
10    name(john).
11    age(42).
12    salary(23500).
13
14:- end_object.
15
16
17:- category(logging,
18    implements(monitoring),     % built-in protocol for event handler methods
19    complements(employee)).     % add the category predicates to the employee object
20
21    % define a "before" event handler for the complemented object:
22    before(This, Message, Sender) :-
23        this(This),
24        write('Received message '), writeq(Message), write(' from '), writeq(Sender), nl.
25
26    % add a new method to the complemented object:
27    :- public(predicates/1).
28
29    predicates(Predicates) :-
30        setof(Predicate, ::current_predicate(Predicate), Predicates).
31
32    % define an alias for a predicate of the complemented object:
33    :- alias(employee, salary/1, income/1).
34
35:- end_category.
Note: See TracBrowser for help on using the browser.