ECLiPSe offers the possibility to store references to general terms and to access them even inside predicates that have no common variables with the predicate that has stored them. They are stored in so-called references. For example,
:- local reference(p).creates a named reference p which can be used to store references to terms. This reference is accessed and modified in the same way as non-logical variables, with setval/2 and getval/2, but the following points are different for references:
[eclipse 1]: local reference(a), variable(b). yes. [eclipse 2]: Term = p(X), setval(a, Term), getval(a, Y), Y == Term. X = X Y = p(X) Term = p(X) yes. [eclipse 3]: Term = p(X), setval(b, Term), getval(b, Y), Y == Term. no (more) solution.
[eclipse 4]: setval(a, 1), (setval(a, 2), getval(a, X); getval(a, Y)). X = 2 Y = Y More? (;) X = X Y = 1
There is only a limited number of references available and their use should be considered very carefully. Their misuse can lead to very bad programs which are difficult to understand and difficult to optimize.