add call_residue_vars (SWI and SICStus 4 compatibility).

This commit is contained in:
Vitor Santos Costa 2009-05-13 16:43:24 -05:00
parent bddc09b963
commit 04fa96e8a0
3 changed files with 42 additions and 1 deletions

View File

@ -12097,6 +12097,23 @@ no
The system only reports one invocation of @code{dif/2} as having
suspended.
@item call_residue_vars(:@var{G},@var{L})
@findex call_residue_vars/2
@syindex call_residue_vars/2
@cnindex call_residue_vars/2
Call goal @var{G} and unify @var{L} with a list of all constrained variables created @emph{during} execution of @var{G}:
@example
?- dif(X,Z), call_residue_vars(dif(X,Y),L).
dif(X,Z), call_residue_vars(dif(X,Y),L).
L = [Y],
dif(X,Z),
dif(X,Y) ? ;
no
@end example
@end table
@node Attributed Variables, CLPR, Co-routining, Extensions

View File

@ -560,6 +560,29 @@ frozen(V, LG) :-
'$fetch_same_done_goals'(G0, D0, LV, GF).
call_residue_vars(Goal,Residue) :-
attributes:all_attvars(Vs0),
call(Goal),
attributes:all_attvars(Vs),
% this should not be actually strictly necessary right now.
% but it makes it a safe bet.
sort(Vs, Vss),
sort(Vs0, Vs0s),
'$ord_remove'(Vss, Vs0s, Residue).
'$ord_remove'([], _, []).
'$ord_remove'([V|Vs], [], [V|Vs]).
'$ord_remove'([V1|Vss], [V2|Vs0s], Residue) :-
( V1 == V2 ->
'$ord_remove'(Vss, Vs0s, Residue)
;
V1 @< V2 ->
Residue = [V1|ResidueF],
'$ord_remove'(Vss, [V2|Vs0s], ResidueF)
;
'$ord_remove'([V1|Vss], Vs0s, Residue)
).
call_residue(Goal,Residue) :-
var(Goal), !,
'$do_error'(instantiation_error,call_residue(Goal,Residue)).
@ -569,7 +592,7 @@ call_residue(Module:Goal,Residue) :-
call_residue(Goal,Residue) :-
'$current_module'(Module),
'$call_residue'(Goal,Module,Residue).
'$call_residue'(Goal,Module,Residue) :-
'$read_svar_list'(OldAttsList),
copy_term_nat(Goal, NGoal),

View File

@ -512,6 +512,7 @@ source_module(Mod) :-
call_cleanup(:,:),
call_cleanup(:,?,:),
call_residue(:,?),
call_residue_vars(:,?),
catch(:,+,:),
clause(:,?),
clause(:,?,?),