Next: , Previous: , Up: mpg-bpr   [Contents][Index]


11.3.144 numbervars/3

Synopsis

numbervars(+Term, +FirstVar, -LastVar)

instantiates each of the variables in Term to a term of the form '$VAR'(N).

Arguments

Term

term

FirstVar

integer, must be nonvar

LastVar

integer

Description

FirstVar is used as the value of N for the first variable in Term (starting from the left). The second distinct variable in Term is given a value of N satisfying “N is FirstVar+1”; the third distinct variable gets the value FirstVar+2, and so on. The last variable in Term has the value LastVar-1.

Notice that in the example below, write_canonical/1 is used rather than writeq/1. This is because writeq/1 treats terms of the form '$VAR'(N) specially; it writes ‘A’ if N=0, ‘B’ if N=1, …‘Z’ if N=25, ‘A1’ if N=26, etc. That is why, if you type the goal in the example below, then the variable bindings will also be printed out as follows:

Term = foo(W,W,X),
A = W,
B = X

Exceptions

instantiation_error

FirstVar is uninstantiated

type_error

FirstVar is not an integer

Examples

| ?- Term = foo(A, A, B), numbervars(Term, 22, _), write_canonical(Term).
foo('$VAR'(22),'$VAR'(22),'$VAR'(23))

See Also

ref-lte-anv, write_term/[2,3].


Send feedback on this subject.