prolog trace how to use

浪子不回头ぞ 提交于 2019-12-23 19:01:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!