This library module provides miscellaneous operations on terms. Exported predicates:
This predicate is identical to the built-in
and it is only present for backwards compatibility.
In many cases, binding variable is not really desirable, in which case
subsumes_term/2 should be used instead.
If unification is in fact wanted, it may be better to make this explicit in your code by
subsumes_term/2 followed by an explicit unification, e.g.
term_hash(Term, , Hash).
jenkins. This is the default. If we ever see a need to change the default hash algorithm again then the algorithm denoted by
defaultmay change but the algorithm denoted by the other names, like
'sicstus-4.0.5', will not change.
This algorithm produces hash values that may differ
jenkins. I.e. the default since SICStus Prolog 4.0.5. Note that this atom needs to be quoted.
there are some other (not as good) algorithms available for the curious, see the source for detail.
Unless otherwise noted, the hash value will be identical across
runs and platforms.
2^28on 32-bit platforms and
2^60on 64-bit platforms.
smallint32. This is the default. This ensures that, by default, the same hash value is computed for the same term on both 32-bit and 64-bit platforms.
Depthis a non-negative integer the subterms up to depth Depth of Term are used in the computation. Alternatively, if
Depthis the atom
infinite, all subterms of Term are relevant in computing Hash. In the latter case Term must be acyclic. In this context the depth of a term is defined as follows: the (principal functor of) the term itself has depth 1, and an argument of a term with depth i has depth i+1. Note that this is similar to, but not the same as, the value computed by
term_depth/2. For legacy reasons a Depth of -1 is treated the same a
Hashis bound to
Value. There is no restrictions on
Value, it need not be an integer or even be ground.
term_hash/3just succeeds without binding
Hash. This is the default. This is useful when the hash value us used for first-argument indexing. This ensures that if the (possibly variable-valued) hash values for Term1 and Term2 are Hash1 and Hash2, respectively, then if Term1 and Term2 are unifiable (to the specified depth) then so are Hash1 and Hash2. For other use cases it is probably more appropriate to specify
term_hash/[2,3,4]is provided primarily as a tool for the construction of sophisticated Prolog clause access schemes. Its intended use is to generate hash values for terms that will be used with first argument clause indexing, yielding compact and efficient multi-argument or deep argument indexing. Note that, for this usage, it is very important that the hash value is a small integer, as it will be by default.
)since release 4.3
This was called
term_variables/2 prior to SICStus Prolog
4.3 but now
term_variables/2 is a built-in with different
meaning, due to alignment with the ISO Prolog standard.
This predicate has been superseeded by the built-in
term_variables/2 and it is only present for backwards compatibility.
The name is an historical accident, the result is not really a bag (i.e. multiset).
>according as X @< Y, X == Y, or X @> Y. This is the same as
compare/3, except for the argument order.
sub_term/2and then test them with this routine. If you just want to find out whether Kernel occurs in Expression or not, use
==to check for the variable (
=) so it can be used to check for arbitrary terms, not just variables.
sub_term/2and then test them with this routine. If you just want to find out whether Variable occurs in Term or not, use
term_depth(Var) = 0 term_depth(Const) = 0 term_depth(F(T1,...,Tn)) = 1+max(term_depth(T1),...,term_depth(Tn))
Could be defined as:
term_depth(X, Depth) :- simple(X), !, Depth = 0. term_depth(X, Depth) :- ( foreacharg(A,X), fromto(0,D0,D,Depth0) do term_depth(A, D1), D is max(D0,D1) ), Depth is Depth0+1.
term_size(X, Size) :- var(X), !, Size = 0. term_size(X, Size) :- simple(X), !, Size = 1. term_size(X, Size) :- ( foreacharg(A,X), fromto(1,S0,S,Size) do term_size(A, S1), S is S0+S1 ).
same_functor/3, at least one of T1 and T2 must be bound, or an error will be reported.