3

我的一个项目需要 swipl 控制台输出(跟踪输出)。我正在尝试使用 JPL7 API 来执行此操作,但我似乎找不到从 swipl 控制台获取输出的方法。有没有办法我可以做到这一点?或者是否有一个我可以运行的查询将跟踪输出定向​​到一个文件,然后从那里工作?

提前致谢。

4

1 回答 1

2

你可以尝试使用协议/1,然后开始你的查询前缀leash(-all),trace

编辑解决方案(?)以更改回溯文件:我将保存在一个模块中(可能命名为 trace_protocol :-),然后使用 with?- [trace_protocol].和随后?- trace,trace_protocol(append(X,Y,[1,2,3])).

:- meta_predicate trace_protocol(0).

trace_protocol :-
    Name = trace_protocol_index,
    catch(nb_getval(Name, N), _Exc, nb_setval(Name, 0)),
    % writeln(ex:Exc), 
    nb_current(Name, N),
    % writeln(nb_current(Name, N)), 
    M is N+1, nb_setval(Name, M),
    % writeln(nb_setval(Name, M)),
    format(atom(PN), '~s_~d.tty', [Name, N]),
    % writeln(trace_protocol:PN),
    protocol(PN).

trace_protocol(Q) :- trace_protocol, forall(Q, trace_protocol).

编写代码花了很多时间,因为 nb_current/2 中似乎有一个错误。不应该,但它会引发异常 - 实际上异常是从库(clpfd)中引发的,即使它没有直接包含在我的测试模块中。

例如,顺序编号的 *.tty 文件最好在终端中显示

$ cat *.tty

因为有 TTY 格式的转义序列。也许这样的序列可以被拒绝?- set_prolog_flag(color_term, false).

于 2016-05-03T07:05:49.827 回答