Re: Stuck on cut problem

From: Danilo Hoffmann (dhhyi_at_web.de)
Date: 02/22/04


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.



Relevant Pages

  • Re: Rounding time to the next minute
    ... "Paul D" schrieb im Newsbeitrag ... > Rounding time to the next minute ...
    (microsoft.public.excel.misc)
  • Re: need to determine a text value of a field based upon a number
    ... Frank Kabel ... "Paul D" schrieb im Newsbeitrag ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Inactive record
    ... --- "Paul" schrieb im Newsbeitrag ... > Hi just wondering if there is a way to have one record in a table be read> only, were an application can not remove it and have all other records act> normally? ...
    (microsoft.public.sqlserver.security)
  • Re: Cannot Map Network drives
    ... You can see the other clients, but not the shares if you dblClick them? ... "Paul D" schrieb im Newsbeitrag ...
    (microsoft.public.windows.server.sbs)
  • Re: Wireless settings
    ... I just thought Ethman would be a solution, because a note in MSDN says: ... When Ethman adds a wireless adapter, a dialog box that allows the user ... Paul G. Tobey schrieb: ...
    (microsoft.public.windowsce.embedded.vc)