diff --git a/docs/yap.tex b/docs/yap.tex index 3db96a16c..fe8652dd1 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -3257,6 +3257,15 @@ structure. All suspended goals and attributes for attributed variables in @var{TI} are also duplicated. Also refer to @code{copy_term/2}. + +@item copy_term(?@var{TI},-@var{TF},-@var{Goals}) +@findex copy_term/3 +@syindex copy_term/3 +@cnindex copy_term/3 +Term @var{TF} is a variant of the original term @var{TI}, such that for +each variable @var{V} in the term @var{TI} there is a new variable @var{V'} +in term @var{TF}. Attributed variables are converted to standard variables and the list @var{Goals} is unified with a set of goals that can be used to restore the constraints, by calling @code{attribute_goals/3} before copying is performed. + @end table @node Predicates on Atoms, Predicates on Characters, Testing Terms, Top diff --git a/pl/corout.yap b/pl/corout.yap index 69d236896..9a9ae5dcc 100644 --- a/pl/corout.yap +++ b/pl/corout.yap @@ -583,6 +583,22 @@ call_residue_vars(Goal,Residue) :- '$ord_remove'([V1|Vss], Vs0s, Residue) ). +copy_term(Term, Copy, Goals) :- + term_variables(Term, TVars), + '$pick_vars_for_project'(TVars,AttVars), + '$call_attribute_goals'(AttVars, Goals0, LDs), + '$fetch_delays_and_simplify'(AttVars, LDs, LGs), + '$convert_att_vars'(AttVars, LGs), + copy_term_nat([Term|Goals0], [Copy|Goals]). + +'$fetch_delays_and_simplify'(AttVars, LDs, LGs) :- + '$fetch_delays'(AttVars, LDs0, LGs), + '$fetch_delays_simplify'(LDs0, LDs). + +'$fetch_delays_simplify'(LDs0, LDs0) :- var(LDs0), !. +'$fetch_delays_simplify'([_-G|LDs0], [G|LDs0]) :- + '$fetch_delays_simplify'(LDs0, LDs0). + call_residue(Goal,Residue) :- var(Goal), !, '$do_error'(instantiation_error,call_residue(Goal,Residue)).