簡單的硬編碼方式:
pretty_print([A, B, C, D, E, F, G, H, I]) :-
write(=============), nl, nl,
write('= '), write(A), write(' = '), write(B), write(' = '), write(C), write(' ='), nl, nl,
write(=============), nl, nl,
write('= '), write(D), write(' = '), write(E), write(' = '), write(F), write(' ='), nl, nl,
write(=============), nl, nl,
write('= '), write(G), write(' = '), write(H), write(' = '), write(I), write(' ='), nl, nl,
write(=============), nl, nl.
與格式:
pretty_print(L) :-
format('=============~n
= ~w = ~w = ~w =~n
=============~n
= ~w = ~w = ~w =~n
=============~n
= ~w = ~w = ~w =~n
=============', L).
一些functionnal幫助:
length_(A, B) :- length(B, A).
pretty_print(L) :-
length(Rows, 3),
maplist(length_(3), Rows),
append(Rows, L),
maplist(format('=============~n~n= ~w = ~w = ~w =~n~n'), Rows),
write(=============), nl.
與lambda模塊:
pretty_print(L) :-
length(Rows, 3),
maplist(\X^length(X, 3), Rows),
append(Rows, L),
maplist(format('=============~n~n= ~w = ~w = ~w =~n~n'), Rows),
write(=============), nl.
用法:
?- initial(X), pretty_print(X).
或
?- goal(X), pretty_print(X).