YAP 7.1.0
nb_setarg/3

nb_setarg(+{Arg], + Term, + Value) More...

Detailed Description

nb_setarg(+{Arg], + Term, + Value)

Assigns the Arg-th argument of the compound term Term with the given Value as setarg/3 , but on backtracking the assignment is not reversed If Term is not atomic, it is duplicated using duplicate_term/2 This predicate uses the same technique as nb_setval/2 We therefore refer to the description of nb_setval/2 for details on non-backtrackable assignment of terms This predicate is compatible to GNU-Prolog setarg(A,T,V,false), removing the type-restriction on Value See also nb_linkarg/3 Below is an example for counting the number of solutions of a goal Note that this implementation is thread-safe, reentrant and capable of handling exceptions Realising these features with a traditional implementation based on assert/retract or flag/3 is much more complicated

succeeds_n_times(Goal, Times) :-
Counter = counter(0),
( Goal,
arg(1, Counter, N0),
N is N0 + 1,
nb_setarg(1, Counter, N),
fail
; arg(1, Counter, Times)
).

The documentation for this class was generated from the following file: