Re: Parise P. - writing a predicate

Merinov Nikolay <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
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
> [email protected]
> https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.