Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I have a doubt in SWI-Prolog. L and C are line and column respectively. I want that swi-prolog consider the numeric value of C-1. Is there any function to do this. the result of the query must be yes. q(9,8). p(L,C) :- q(L,C-1). ?-p(9,9) No Thanks in advance SRocha
Post Follow-up to this messageSRocha schreef in comp.lang.prolog: > Hi, > > I have a doubt in SWI-Prolog. L and C are line and column respectively. > I want that swi-prolog consider the numeric value of C-1. Is there any > function to do this. > the result of the query must be yes. > > q(9,8). > p(L,C) :- q(L,C-1). > > ?-p(9,9) > No Try this: q(9,8). p(L,C):- D is C - 1, q(L,D). ?- p(9,9). Yes greetz Wouter -- http://www.ligezin.be/
Post Follow-up to this message
"SRocha" <msmr@netcabo.pt> wrote in message
news:429b6890$0$9644$a729d347@news.telepac.pt...
> Hi,
>
> I have a doubt in SWI-Prolog. L and C are line and column respectively.
> I want that swi-prolog consider the numeric value of C-1. Is there any
> function to do this.
> the result of the query must be yes.
>
> q(9,8).
> p(L,C) :- q(L,C-1).
>
> ?-p(9,9)
> No
>
Well another poster has already given the answer, use 'is', but it
is a good idea to understand why it was failing. Take a look at what
unified with Y.
q(X,Y):- write('X='),write(X),
write(',Y='),write(Y),
Z is Y, % <-------------and think about this clause
write(',Z='),write(Z).
p(L,C):- q(L,C-1).
p(9,9).
X=9,Y=9-1,Z=8
--
Geoff
Post Follow-up to this messageIn prolog, C-1 is not evaluated if you don't say so explicitely, with the keyword "is": p(L,C) :- Result is C-1, q(L, Result). Until you use the keyword "is", C-1 is considered as a sequence of three symbols: C, -, 1 Cheers, Maurizio
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.