Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with SWI-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

Thanks in advance

SRocha



Report this thread to moderator Post Follow-up to this message
Old Post
SRocha
05-31-05 01:57 AM


Re: Problem with SWI-Prolog
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/

Report this thread to moderator Post Follow-up to this message
Old Post
Ligezin
05-31-05 01:57 AM


Re: Problem with SWI-Prolog
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Geoffrey Summerhayes
05-31-05 09:01 PM


Re: Problem with SWI-Prolog
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


Report this thread to moderator Post Follow-up to this message
Old Post
seguso
06-06-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:35 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.