diff --git a/Logtalk/examples/msglog/NOTES b/Logtalk/examples/msglog/NOTES new file mode 100644 index 000000000..e538ffe8c --- /dev/null +++ b/Logtalk/examples/msglog/NOTES @@ -0,0 +1,13 @@ +================================================================= +Logtalk - Object oriented extension to Prolog +Release 2.15.1 + +Copyright (c) 1998-2003 Paulo Moura. All Rights Reserved. +================================================================= + +To load all objects in this library consult the msglog.loader utility +file (note that the *.loader files are Prolog files). + +If you need more than one message recorder, just create a new prototype +as an extension of the object msglog. + diff --git a/Logtalk/examples/msglog/SCRIPT b/Logtalk/examples/msglog/SCRIPT new file mode 100644 index 000000000..c2be637df --- /dev/null +++ b/Logtalk/examples/msglog/SCRIPT @@ -0,0 +1,46 @@ +================================================================= +Logtalk - Object oriented extension to Prolog +Release 2.15.1 + +Copyright (c) 1998-2003 Paulo Moura. All Rights Reserved. +================================================================= + +% assume that all library entities have been loaded... + +% start recording user messages: + +| ?- msglog::record. + +yes + +% send some messages: + +| ?- list::member(X, [1, 2, 3]). + +X = 1 ; +X = 2 ; +X = 3 ; +no + +| ?- character::is_alpha(p). + +yes + +| ?- integer::between(1, 4, N). + +N = 1 ; +N = 2 ; +N = 3 ; +N = 4 ; +no + +% stop recording and print message log: + +| ?- msglog::(stop, print). + +list::member(X, [1, 2, 3]). +character::is_alpha(p). +integer::between(1, 4, N). + +yes + diff --git a/Logtalk/examples/msglog/msglog.lgt b/Logtalk/examples/msglog/msglog.lgt new file mode 100644 index 000000000..cfdb3adac --- /dev/null +++ b/Logtalk/examples/msglog/msglog.lgt @@ -0,0 +1,82 @@ + +:- object(msglog). + + + :- info([ + version is 1.0, + author is 'Paulo Moura', + date is 2003/03/04, + comment is 'Monitor for recording, replaying, and saving user messages.']). + + + :- public(record/0). + :- mode(record, one). + :- info(record/0, + [comment is 'Starts recording messages.']). + + :- public(stop/0). + :- mode(stop, one). + :- info(stop/0, + [comment is 'Stops recording messages.']). + + :- public(replay/0). + :- mode(replay, one). + :- info(replay/0, + [comment is 'Replays all recorded messages.']). + + :- public(print/0). + :- mode(print, one). + :- info(print/0, + [comment is 'Prints recorded messages, one per line.']). + + :- public(erase/0). + :- mode(erase, one). + :- info(erase/0, + [comment is 'Erases recorded messages.']). + + + :- private(log_/2). + :- dynamic(log_/2). + :- mode(log_(+object, +nonvar), zero_or_more). + :- info(log_/2, + [comment is 'Table of recorded messages.', + argnames is ['Object', 'Message']]). + + + record :- + self(Self), + abolish_events(_, _, _, _, Self), + define_events(before, _, _, user, Self). + + + stop :- + self(Self), + abolish_events(_, _, _, _, Self). + + + replay :- + self(Self), + abolish_events(_, _, _, _, Self), + forall(::log_(Object, Message), {Object::Message}). + + + print :- + forall( + ::log_(Object, Message), + (writeq(Object), write('::'), writeq(Message), write('.'), nl)). + + + erase :- + ::retractall(log_(_, _)). + + + before(Object, Message, _) :- + self(Self), + (Self = Object -> + true + ; + ::assertz(log_(Object, Message))). + + +:- end_object. + diff --git a/Logtalk/examples/msglog/msglog.loader b/Logtalk/examples/msglog/msglog.loader new file mode 100644 index 000000000..b93d0b700 --- /dev/null +++ b/Logtalk/examples/msglog/msglog.loader @@ -0,0 +1,4 @@ + +:- initialization( + logtalk_load([ + msglog])).