-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog_angry_man.pl
More file actions
34 lines (31 loc) · 900 Bytes
/
Copy pathlog_angry_man.pl
File metadata and controls
34 lines (31 loc) · 900 Bytes
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
:- ensure_loaded(angry_man).
pretty_print_to(_, []).
pretty_print_to(Stream, [Note|Tail]) :-
Note = note{name: Name, accidental: Accidental, octave: Octave},
write(Stream, Name), write(Stream, '_'),
write(Stream, Accidental), write(Stream, '_'),
write(Stream, Octave),
write(Stream, ' '),
pretty_print_to(Stream, Tail).
log_rows(Stream, Limit) :-
nb_setval(row_count, 0),
length(Row, 12),
angry_man_row(Row),
nb_getval(row_count, N),
N1 is N + 1,
nb_setval(row_count, N1),
pretty_print_to(Stream, Row),
nl(Stream),
flush_output(Stream),
N1 >= Limit, !.
log_rows(_, _).
main :-
File = 'angry_man_rows.log',
Limit = 100,
setup_call_cleanup(
open(File, write, Stream),
log_rows(Stream, Limit),
close(Stream)
),
nb_getval(row_count, Total),
format("Wrote ~w rows to ~w~n", [Total, File]).