Array Univ var ([x, y] = .. T) - prolog

I asked what returns [a,b,c]=..L.. When testing, I saw that it returns: L = ['.', a, [b, c]].

I can’t understand why this is happening, I couldn’t understand the nature of Univ from the documentation . Understanding this will help me understand Univ.

+4
source share
2 answers

This is because the list view in the prolog is a datastructure tree like this. enter image description hereThis is the top of the node - this is the “point”, on the left is the head, and then again the point on the right if the tail is not empty and the head is on the left and the “point” on the right hand. When you do this, you simply create a predicate (well, not an exact predicate, but sometimes it is necessary, as I give an example): suppose I write:

V=..[somefunctor,X,Y,Z]  

Then it will automatically construct the predicate as follows:

   somefunctor(X,Y,Z).

? , : predicate(somefunctor,term,term2,term3) : predicate(X,Y,Z,T) , , X, Y,Z,T. , , , : X(Y,Z,T), , , , V =.. [X, Y, Z, T], X , , - : V = somefunctor(term,term2,term3), . , :

call(V) where `call/1` is a metapredicate and `V=..`  is a not logical predicate.
+2

- write_canonical/1 Prolog  

, GNU Prolog :

| ?- write_canonical([x,y]).
'.'(x,'.'(y,[]))

:

  • '.', arity 2
  • x
  • '.'(y, []), [y]

, (=..)/2 :

| ?- [x,y] =.. Ls.

Ls = ['.',x,[y]]

.

+5

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


All Articles