File: msglog.lgt

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (82 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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.