The following example shows how to attach a finite-domain to a variable:
create_fd_variable(X,D):-
put_attr_no_hook(X,fd,D),
check_value(X,D).
check_value(X,D),var(X),{ins(X)} => true.
check_value(X,D) => member(X,D).
The agent check_value(X,D) is activated in order to check whether the value is in the domain when X is instantiated. This predicate can be equivalently defined as follows:
create_fd_variable(X,D):-
put_attr(X,fd,D).
attr_unify_hook(X,fd,D):-member(X,D).