Getting started with Prolog and obviously a fundamental misunderstanding of how this works, help?

I run my first few programs in Prolog and got trapped in an experiment that I am trying to run. I initially did this on a mini map of several states of the USA, but I simplified it to the alphabet:

adj(a,b).
adj(b,a).
adj(b,c).
adj(c,b).
adj(c,d).

na(X, Z) :- \+adj(X, Z).

When I request na (a, What). I don't get any answers (just not), but if I individually check na (a, d) it certainly naturally returns yes.

What is the explanation why this will happen? I was able to get other requests to work in different programs, so I wonder what key information I miss. Thank!

+3
source share
1 answer

(\ +)/1 , " ". \+ na(a, What) , na(a, What) . na(a, What) , , , ( ) . (\ +)/1, , : , , , , . (\ +/1) , , . , ,

na(X, Y) :- country(X), country(Y), \+ adj(X, Y).

/1 . - , , , . , : , , ( (\ +)/1, ). .

+6

Source: https://habr.com/ru/post/1791257/


All Articles