是否可以使用 prologformat谓词打印到文件?
我有一个数据表,我使用格式谓词打印到标准输出,即
print_table :-
print_table_header,
forall(range(1.0,10.0,0.1,N), print_row(N,L)).
%% print_row(L) :- take a list of the form, [a,b,c,d,e] and
%% print it to screen as a single row of tab separated float values (1DP)
print_row(N,L) :-
build_row(N,L),
format('~t~1f~10+ ~t~1f~10+ ~t~1f~10+ ~t~1f~10+ ~t~1f~10+ ~n', L).
print_table_header :-
format('~t~w~10+ ~t~w~10+ ~t~w~10+ ~t~w~10+ ~t~w~10+ ~n', ['N','N2','N3','N4','N5']).
Run Code Online (Sandbox Code Playgroud)
如果能以某种方式重用代码来将相同的内容打印到文件中,那就太好了。
你可以!
请考虑以下SICStus Prolog 文档format/[2,3]摘录:
11.3.85 格式/[2,3]
概要
格式(+控制,+参数)
格式(+流、+控制、+参数)
根据控制字符串解释参数并将结果打印在流上。
这些谓词format/[2,3]在 Prolog 实现中得到广泛支持。
然而,截至目前,这些谓词还不是 ISO Prolog 的一部分。
| 归档时间: |
|
| 查看次数: |
1249 次 |
| 最近记录: |