在swish控制台中跟踪它:
% Handover to indenting predicate
isInteger(X) :- isInteger(X,0).
% As isInteger(), with printouts
isInteger(0,I) :- ws(I), format('0 reached\n').
isInteger(X,I) :- wrout('>', X,Y,I), ID is I+1, isInteger(Y,ID), wrout('<', X,Y,I), X is Y+1, wsucc(I).
% Writing out
wrout(C,X,Y,I) :-ws(I),format('~a X=',C),write(X),format(',Y='),write(Y),format('\n').
% Writing "success"
wsucc(I) :- ws(I),format('success\n').
% Indenting by 2*N underscores
ws(0).
ws(N) :- N>0, format('__'), ND is N-1, ws(ND).
通过检查 2 是否为整数? - isInteger(2).
(但不要为此调用 Next,否则将发生永无止境的搜索!)
> X=2,Y=_G5707
__0 reached
< X=2,Y=0
__> X=_G5707,Y=_G6473
____0 reached
__< X=_G5707,Y=0
__success
< X=2,Y=1
success
true
使用枚举整数?- isInteger(I)
0 reached
I = 0
“下一个”
> X=_G5328,Y=_G5926
__0 reached
< X=_G5328,Y=0
success
I = 1
“下一步”(注意我们在缩进 '__' 处重新开始)
__> X=_G5926,Y=_G391
____0 reached
__< X=_G289,Y=0
__success
< X=_G257,Y=1
success
I = 2
“下一步”(注意我们在缩进 '____' 处重新开始)
____> X=_G391,Y=_G3260
______0 reached
____< X=_G391,Y=0
____success
__< X=_G289,Y=1
__success
< X=_G257,Y=2
success
I = 3
非常好。
我将向当地团队解释这一点。这是一个带有一些“原始符号”的整数枚举过程的说明。希望不言自明。