Re: Stuck on cut problem
From: Danilo Hoffmann (dhhyi_at_web.de)
Date: 02/22/04
- Next message: pekka: "Prolog for circuit simulation, realtime?"
- Previous message: Martin Fuchs: "Re: [OT] GNU-Prolog: builduing executables in Win32 platform"
- In reply to: Paul: "Stuck on cut problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 22 Feb 2004 13:34:01 +0100
"Paul" <paul_nospam@laberg.com.au> schrieb im Newsbeitrag
news:4037d43f_1@news.iprimus.com.au...
> 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.
>
>
Try This:
sum_to(1,1) :- !.
sum_to(N,Res) :- N1 is N - 1, sum_to(N1, ResT), Res is ResT + N.
- Next message: pekka: "Prolog for circuit simulation, realtime?"
- Previous message: Martin Fuchs: "Re: [OT] GNU-Prolog: builduing executables in Win32 platform"
- In reply to: Paul: "Stuck on cut problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|