users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parise P. - writing a predicate


From: Merinov Nikolay
Subject: Re: Parise P. - writing a predicate
Date: Sun, 25 Sep 2011 17:23:19 +0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Hi, Paolo.

Exception raised because right part of is/2 not fully instantiated. You
can use gprolog FD solver for your code like this:

adjacent(L1,L2) :- location_toward(L1,L2).
location_toward([X,Y],[New_X,Y]) :- New_X #=# X+1.
location_toward([X,Y],[X,New_Y]) :- New_Y #=# Y+1.
location_toward([X,Y],[New_X,Y]) :- New_X #=# X-1.
location_toward([X,Y],[X,New_Y]) :- New_Y #=# Y-1.

Thanks,
Nikolay Merinov.

> Hi,
> I'm trying implementing a predicate adjacent(W, Z) such that cell W ([X1,Y1])
> is adjacent Z([X2,Y2]) iff:
> X1 = X2 + 1 or X1 = X2 -1 or Y1 = Y2 + 1 or Y1 = Y2 -1 .
> This predicate is used into an algorithm that make these two questions:
> - given cell W, what are the cell Z adjacent to W?
> - given cell Z, what are the cells W adjacent to Z?
> I proposed the following solution:
>
> adjacent(L1,L2) :- location_toward(L1,_,L2).
> location_toward([X,Y],[New_X,Y]) :- New_X is X+1.
> location_toward([X,Y],[X,New_Y]) :- New_Y is Y+1.
> location_toward([X,Y],[New_X,Y]) :- New_X is X-1.
> location_toward([X,Y],[X,New_Y]) :- New_Y is Y-1.
>
> Calling the predicate in the form:
> adjacent([1,1],Z) it lists all the adjacents cells (correct!)
> adjacent(W,[1,2]) it gives these exception:
>
> {trace}
> | ?- adjacent(X,[1,1]).
>       1    1  Call: adjacent(_16,[1,1]) ?
>       2    2  Call: location_toward(_16,_51,[1,1]) ?
>       3    3  Call: 1 is _77+1 ?
>       3    3  Exception: 1 is _77+1 ?
>       2    2  Exception: location_toward(_16,_51,[1,1]) ?
>       1    1  Exception: adjacent(_16,[1,1]) ?
> uncaught exception: error(instantiation_error,(is)/2)
>
> Any suggestions?
>
> Thanks!
>
> Paolo P.
>
>  
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/users-prolog




reply via email to

[Prev in Thread] Current Thread [Next in Thread]