PLOGHELP UNIV Robert Duncan, March 1988 :- op(40, xfx, '=..'). ?- T =.. L . The infix operator '=..' (pronounced "univ") can be used either to decompose a term into a list containing its functor and arguments or else to construct a term from such a list. In a goal of the form ?- T =.. L . if T is a term, then L is unified with a list consisting of the functor of T and its arguments. So for example: ?- p(0, a) =.. L . L = [p, 0, a] ? yes If T is atomic, then it counts as its own functor and L is unified with a singleton list: ?- 3 =.. L . L = [3] ? yes If T is a variable, then L must be instantiated to a proper list (i.e one terminated by nil) whose head is atomic; in this case T is unified with a term constructed from the elements of L, the first element of L being the functor and the remaining elements its arguments. Thus: ?- T =.. [p, 0, a]. T = p(0, a) ? yes ?- T =.. [3]. T = 3 ? yes It is an error for both T and L to be uninstantiated, or for T to be uninstantiated and L not to be a proper list. Also, if the head of L is not an atom, then its tail must be nil in order to construct a term, since objects other than atoms cannot be used as functors of arity greater than zero. A "univ" goal cannot be re-satisfied. An alternative approach to constructing and destructing terms is to use functor/3 and arg/3 (see PLOGHELP * FUNCTOR, * ARG). These can be written in terms of "univ" and vice-versa. -- RELATED DOCUMENTATION ---------------------------------------------- PLOGHELP * ARG Determines the nth argument of a term PLOGHELP * DOLLAR Library package which allows variables to stand for predicate names PLOGHELP * FUNCTOR Determines the functor and arity of a term PLOGHELP * OP Discussion of operators and how to declare them PLOGHELP * OPERATORS Summary of the standard operator declarations PLOGHELP * SYMBOLS Summary and index of HELP files for symbolic atoms used in Prolog --- C.all/plog/help/univ ----------------------------------------------- --- Copyright University of Sussex 1988. All rights reserved. ----------