prolog - Difference between X\=Y and dif(X,Y) -


what difference between this:

x \= y 

and piece of code:

dif(x, y) 

i thought should behave same, not. here's example:

n_puta(l, n, x) :- nputa(l, n, 0, x). nputa([], n, c, _) :- n = c. nputa([g|r], n, c, x) :- g = x, nputa(r, n, y, x), c y - 1. nputa([g|r], n, c, x) :- dif(g,x), nputa(r, n, c, x). 

and here calls:

?- n_puta([a,a,b,b,b], 2, x). x = ; false.  ?- n_puta([a,a,b,a,b,b], 3, x). x = ; x = b ; false. 

x should atom occurs n times in list l. if replace dif(g, x) g \= x, don't expected result. can tell me difference between these 2 operators? can use else except dif(g, x)?

this example works prefectly in swi-prolog, doesn't work in amzi! prolog.

dif/2 , (\=)/2 same long arguments ground. dif/2 pure relation works correctly variables , can used in directions. example shows should use dif/2 in case, because use predicate not test, generate solutions. used prolog systems provide dif/2.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -