YAP 7.1.0
SWI Compatible attributes

Detailed Description


 Implementing Attributed Variables and Co-Routining


Class Documentation

◆ copy_term/3

class copy_term/3

copy_term(? TI,- TF,- Goals)

Term TF is a variant of the original term TI, such that for each variable V in the term TI there is a new variable V' in term TF without any attributes attached Attributed variables are thus converted to standard variables Goals is unified with a list that represents the attributes The goal maplist(call, _Goals_) can be called to recreate the attributes

Before the actual copying, copy_term/3 calls attribute_goals/1 in the module where the attribute is defined

◆ call_residue_vars/2

class call_residue_vars/2

call_residue_vars(: G, L)

Call goal G and unify L with a list of all constrained variables created during execution of G:

?- dif(X,Z), call_residue_vars(dif(X,Y),L).
dif(X,Z), call_residue_vars(dif(X,Y),L).
L = [Y],
dif(X,Y) ? ;
call_residue_vars(: G, L)
dif( X, Y)

◆ attribute_goals/3

class attribute_goals/3

attribute_goals(+ Var,- Gs,+ GsRest)

This nonterminal, if it is defined in a module, is used by copy_term/3 to project attributes of that module to residual goals It is also used by the toplevel to obtain residual goals after executing a query

Normal user code should deal with put_attr/3 , get_attr/3 and del_attr/2 The routines in this section fetch or set the entire attribute list of a variables Use of these predicates is anticipated to be restricted to printing and other special purpose operations

◆ call_residue/2

class call_residue/2

call_residue(: G, L)

Call goal G If subgoals of G are still blocked, return a list containing these goals and the variables they are blocked in The goals are then considered as unblocked The next example shows a case where dif/2 suspends twice, once outside call_residue/2 , and the other inside:

?- dif(X,Y),
call_residue((dif(X,Y),(X = f(Z) ; Y = f(Z))), L).
X = f(Z),
L = [[Y]-dif(f(Z),Y)],
dif(f(Z),Y) ? ;
Y = f(Z),
L = [[X]-dif(X,f(Z))],
dif(X,f(Z)) ? ;
call_residue(: G, L)

The system only reports one invocation of dif/2 as having suspended