Previous Up Next

17.6  Attribute Modification

Often an extension must modify the data stored in the attribute to reflect changes in the computation. The usual Prolog way to do this is by reserving one argument in the attribute structure for this next value. before accessing the most recent attribute value this chain of values has to be dereferenced until a value is found whose link is still free. A perfect compiler should be able to detect that the older attribute values are no longer accessed and it would compile these modifications using destructive assignment. Current compilers are unfortunately not able to perform this optimization (some systems can reduce these chains during garbage collection, but until this occurs, the list has to be dereferenced for each access and update). To avoid performance loss for both attribute updating and access, ECLiPSe provides a predicate for explicit attribute update: setarg(I, Term, NewArg) will update the I’th argument of Term to be NewArg. Its previous value will be restored on backtracking.

Libraries which define user-programmable extensions like, e.g., fd usually define predicates that modify the attribute or a part of it, so that an explicit use of the setarg/3 predicate is not necessary.


Previous Up Next