问题
How to go second step when trace prolog program? For example, I want to trace following simple program:
length1([],0).
length1([_X|Xs],N):- length1(Xs,N1), N is N1+1.
I trace program:
?- trace,length([1,2,3],N).
Call: (7) length([1, 2, 3], _G231) ?
Exit: (7) length([1, 2, 3], 3) ? creep
N = 3.
But as we see, it immediately gives answer. But I thought it should be like Call:(8) ... Call:(9) ...
What am I doing wrong?
回答1:
Looking at your goal, you used the built-in length/2
, not your own length1/2
. Built-ins usually can't be traced.
回答2:
after compling your file (example [length_program]. ) you need to write trace. and then run your command, but I guess you are miss spelling the code. you have defined your pred as length1 so you need to put exactly length1 after your trace
来源:https://stackoverflow.com/questions/11355151/prolog-trace-how-to-use