ch07ex06.pro
来自「prolog,人工智能推理程序,运行环境prolog」· PRO 代码 · 共 45 行
PRO
45 行
/*
Turbo Prolog 2.0 Chapter 7, Example Program 6
Copyright (c) 1986, 88 by Borland International, Inc
*/
/* Shows how badcount2 and badcount3 can be fixed by adding cuts to
rule out the untried clauses. These versions are tail recursive. */
predicates
cutcount2(real)
cutcount3(real)
check(real)
clauses
/* cutcount2:
There is a clause that has not been tried
at the time the recursive call is made. */
cutcount2(X) :-
X>=0, !,
write(X),
nl,
NewX = X + 1,
cutcount2(NewX).
cutcount2(_) :-
write("X is negative.").
/* cutcount3:
There is an untried alternative in a
clause called before the recursive call. */
cutcount3(X) :-
write(X),
nl,
NewX = X+1,
check(NewX),
!,
cutcount3(NewX).
check(Z) :- Z >= 0.
check(Z) :- Z < 0.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?