home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
borland
/
jnfb88.arc
/
TAIL.ARC
/
CUTCOUNT.PRO
< prev
next >
Wrap
Text File
|
1987-10-22
|
912b
|
43 lines
/* CUTCOUNT.PRO */
/* 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) :- write(X),
nl,
NewX = X+1,
!,
cutcount2(NewX).
cutcount2(X) :- X < 0,
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.