Prologue: Can you make a predicate behave differently depending on whether the value is land or not?

I have a somewhat complex predicate with four arguments that should work when both the first and last arguments are grounded / not ground, not ground / ground or ground / ground, and the second and third arguments are grounded.

i.e. predicate (A, B, C, D).

I cannot provide my actual code as it is part of the destination.

It works for me mainly, but I get creation errors when A is not grounded, but D is. However, I highlighted a line of code that causes problems. When I change the target order of the predicate, it works when D is grounded and A is not, but it does not work anymore when A is grounded and D is not. I'm not sure there is a way around this.

Is there a way to use both lines of code so that if A is terrestrial, for example, it will use the first line, but if A is not grounded, it will use the second and ignore the first? And vice versa.

+4
source share
1 answer

You can do this, but , almost always, you will violate the declarative semantics of your programs if you do.

Consider a simple example to see how such a nonmonotonic and extra-logical predicate already violates the basic assumptions and typical declarative properties of known predicates, such as the commutativity of conjunctions:

? - ground (X), X = a.
false

, , :

?- X = a, ground(X).
X = a.

- , .

Prolog. , dif/2 CLP (FD), , .

. , .

+4

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


All Articles