Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

prolog

I saw a question asking what does [a,b,c]=..L. return. When testing this I saw that it returns: L = ['.', a, [b, c]].

I can't understand why this happens, I was unable to understand the nature of Univ from the documentation. Understanding this will help me understand Univ.

like image 666
Tomer Avatar asked Mar 07 '23 17:03

Tomer


1 Answers

One way to learn more about terms is to use write_canonical/1 in a conforming Prolog system.

For example, with GNU Prolog, we obtain:

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

This shows:

  1. the primary functor in this term is '.', with arity 2
  2. the first argument is x
  3. the second argument is '.'(y, []), which is the list [y]

This explains why (=..)/2 yields:

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

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

and also your other example.

like image 89
mat Avatar answered Mar 16 '23 11:03

mat