Global Values

SB-Prolog has some primitives that permit the programmer to manipulate global values. These are provided primarily as an efficiency hack, and needless to say, should be used with a great deal of care.

globalset(Term)
globalset/1 (L) Allows the user to save a global value. Term must be bound to a compound term, say p(V). V must be a number or a constant or a variable. If V is a number or a constant, the effect of globalset(p(V)) can be described as:
retract(p(_)), assert(p(V)).
I.e., p is a predicate that when called will, from now on (until some other change by globalset/1), deterministically return V. If V is a variable, the effect is to make V a global variable whose value is accessible by calling p. For example, executing globalset(p(X)) makes X a global variable. X can be set by unification with some other term. On backtracking, X will be restored to its earlier value.

gennum(Newnum)
gennum/1 (L) gennum/1 sets its argument to a new integer every time it is invoked.

gensym(C, Newsym)
gensym/2 (L) gensym/2 sets its second argument to an atom whose name is made by concatenating the name of the atom C to the current gennum number. This new constant is bound to Newsym. For example, if the current gennum number is 37, then the call
| ?- gensym(aaa,X)
will succeed binding X to the atom `aaa37'.