4

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?

false
  • 10,264
  • 13
  • 101
  • 209
Ali Ismayilov
  • 1,707
  • 3
  • 22
  • 37

2 Answers2

6

Looking at your goal, you used the built-in length/2, not your own length1/2. Built-ins usually can't be traced.

twinterer
  • 2,416
  • 1
  • 15
  • 13
1

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

Ramin
  • 891
  • 2
  • 10
  • 16