Compatibility library for term manipulation predicates. Most predicates in this library are provided as SWI-Prolog built-ins.
?- A = a(1,2,3), term_size(A,S). S = 4. ?- A = a(1,2,3), term_size(a(A,A),S). S = 7. ?- term_size(a(a(1,2,3), a(1,2,3)), S). S = 11.
Note that small objects such as atoms and small integers have a size 0. Space is allocated for floats, large integers, strings and compound terms.
Term1 =@= Term2
.==
Skeleton. Term may be cyclic. For example:
?- X = a(X), term_factorized(b(X,X), Y, S). Y = b(_G255, _G255), S = [_G255=a(_G255)].
call(Goal, A1, A2)
is true.call(Goal, ST1, ST2)
succeeds.
Procedurably, the mapping for each (sub) term pair T1/T2
is
defined as:
call(Goal, T1, T2)
succeeds we are done. Note that
the mapping does not continue in T2. If this is desired, Goal
must call mapsubterms/3
explicitly as part of its conversion.Both predicates are implemented using foldsubterms/5.
call(Goal4, SubTerm1, SubTerm2, StateIn, StateOut)
for each subterm, including variables, in Term1. If this call
fails, StateIn and StateOut are the same. This
predicate may be used to map subterms in a term while collecting state
about the mapped subterms. The foldsubterms/4
variant does not map the term.If Arity is 0, Term1 and Term2 are unified with Name for compatibility.