Stuck on cut problem
From: Paul (paul_nospam_at_laberg.com.au)
Date: 02/21/04
- Next message: Amzi! inc.: "ANN: Amzi! 7.0.14 Adds Syntax Assist, Improved Debugging (including DCG)"
- Previous message: Arun Hallan: "A 'fail' predicate"
- Next in thread: Paul: "Re: Stuck on cut problem"
- Reply: Paul: "Re: Stuck on cut problem"
- Reply: Tom Breton: "Re: Stuck on cut problem"
- Reply: Danilo Hoffmann: "Re: Stuck on cut problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 22 Feb 2004 08:56:05 +1100
Simple program from "Programming in Prolog" (Clocksin & Mellish)
sum_to(1,1) :- !.
sum_to(N,Res) :- N1 is N - 1, sum_to(N1, Res), Res is Res + N.
The results are supposed to be:
?- sum_to(5,X).
X = 15;
no
But I get:
?- sum_to(5,X).
no
I have checked and rechecked the code, it gets to the cut and then fails on
"Res is Res + N". I am using SWI Prolog could there be a difference in the
way the cut works? To remove the possibility of the cut causing the problem
I rewrote the program as follows:
sum_to(1,1).
sum_to(N,R) :- not(N=1), N1 is N - 1, sum_to(N1, R), R is R + N.
It is still failing on "R is R + N"
Any ideas would be appreciated.
- Next message: Amzi! inc.: "ANN: Amzi! 7.0.14 Adds Syntax Assist, Improved Debugging (including DCG)"
- Previous message: Arun Hallan: "A 'fail' predicate"
- Next in thread: Paul: "Re: Stuck on cut problem"
- Reply: Paul: "Re: Stuck on cut problem"
- Reply: Tom Breton: "Re: Stuck on cut problem"
- Reply: Danilo Hoffmann: "Re: Stuck on cut problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|