A suspension variable, or an attributed variable, is a variable to which there are suspended agents and attribute values attached. Agents are registered onto suspension variables by action rules. Each attribute has a name, which must be ground, and a value. The built-in put_attr(Var,Attr,Value) is used to register attribute values and the built-in get_attr(Var,Attr,Value) is used to retrieve attribute values.
The unification procedure needs be revisited now that we have attributed variables. When a normal Prolog variable is unified with an attributed variable, the normal Prolog variable will be bound to the attributed variable. When two attributed variables Y and O are unified, suppose Y is younger than O, the following operations will be performed:
- All the agents attached to Y are copied to O.
- An event ins(Y) is posted.
- The variable Y is set to reference the variable O.
Notice that because no attribute is copied the younder variable will lose all of its attributes after unification. Notice also that because of garbage collection, the age ordering of variables is normally unpredicatable.
- attvar(Term): True if Term is an attributed variable.
- put_attr(Var, Attr, Value): Set the value for the attribute named Attr to Value. If an attribute with the same name already exists on Var, the old value is replaced. The setting is undone upon backtracking, same as setarg/3. This primitive also attaches an agent to Var which invokes attr_unify_hook/3 when and ins(Var) is posted.
- put_attr_no_hook(Var, Attr, Value): The same as put_attr(Var, Attr, Value) but it does not attach any agent to Var to call attr_unify_hook/3 when ins(Var) is posted.
- get_attr(Var, Attr, Value) Retreive the current value for the attribute named Attr. If Var is not an attributed variable or no attribute named Attr exists on Var, this predicate fails silently.
- del_attr(Var, Attr): Delete the attribute named Attr. This update is undone upon backtracking.
- frozen(L):
The list of all suspended agents is L.
- frozen(V,L):
The list of suspended agents on the suspension variable V is L.
- constraints_number(X,N):
N is the number of agents attached to the suspension variable X.
Subsections
Neng-Fa Zhou
2012-01-03