p(X,Y) :-
trace_call_port(call,_, Y is X*X-1),
*(X,X,T),
-(T,1,Y),
trace_exit_port.
The trace then looks like this:
Another example is the insertion of additional ports for existing boxes, in particular the current parent box:[eclipse 8]: p(3,Y). (1) 1 CALL p(3, Y) %> creep (2) 2 CALL Y is 3 * 3 - 1 %> skip (2) 2 EXIT 8 is 3 * 3 - 1 %> creep (1) 1 EXIT p(3, 8) %> creep Y = 8
p :-
trace_parent_port(clause1),
writeln(hello),
fail.
p :-
trace_parent_port(clause2),
writeln(world).
This gives rise to the following trace:
Note that the additional ports share the parent's invocation number, so the i command can be used to skip from one to the other.?- p. (1) 1 CALL p %> creep (1) 1 CLAUSE1 p %> creep S (2) 2 CALL writeln(hello) %> creep hello S (2) 2 EXIT writeln(hello) %> creep (3) 2 CALL fail %> creep (3) 2 FAIL fail %> creep (1) 1 NEXT p %> creep (1) 1 CLAUSE2 p %> creep S (4) 2 CALL writeln(world) %> creep world S (4) 2 EXIT writeln(world) %> creep (1) 1 EXIT p %> creep Yes (0.00s cpu)