The univ operator is used for construction or decomposition of terms. The operator succeeds if the right argument is a list L that contains the functor of the left operand of =.. followed by its arguments.
With this operator it is possible to construct heads of clauses or to analyse them, in the file 'system.txt', that contains some of the standard built-in predicates of Trinc-Prolog, there are some nice examples of how =../2 can be used.
see also: arg/3 copy_term/2 freeze/2 functor/3 melt/3 number_vars/3
| Examples | |
| f(a,b) =.. [X | Y]. | succeeds, X=f, Y=[a,b] |
| f(a(z),b,c) =.. L. | succeeds, L=[f, a(z), b, c] |
| X =.. [g, a, b(z)]. | succeeds, X=g(a,b(z)) |
| f(a,b) =.. [f, b, a]. | fails |
| foo(a,b) =.. [foo(X,Y)]. | fails |
| number_vars(Term, N, M) :- Term =.. [_|Args], numberargs(Args, N, M). |
The first argument 'Term' is decomposed by =../2, the first element of the list that =../2 produces is the functor of the term. The functor is ignored in this example by unifying it with an anonymous variable, the tail of the list is a list of arguments. The list of arguments of the term can then be easily analysed by numberargs/3. |