For Programmers: Free Programming Magazines  


Home > Archive > Prolog > June 2005 > Problem with SWI-Prolog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with SWI-Prolog
SRocha

2005-05-30, 8:57 pm

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


Ligezin

2005-05-30, 8:57 pm

SRocha 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/
Geoffrey Summerhayes

2005-05-31, 4:01 pm


"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


seguso

2005-06-05, 8:57 pm

In 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com