diff: extras/trailed_update/var.m: var__is_ground/2
Fergus Henderson
fjh at hydra.cs.mu.oz.au
Tue Nov 11 22:14:30 AEDT 1997
extras/trailed_update/var.m:
Add new predicate var__is_ground/2.
Any comments?
[I have test cases for this coming soon.]
cvs diff extras/trailed_update/var.m
Index: extras/trailed_update/var.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/extras/trailed_update/var.m,v
retrieving revision 1.7
diff -u -r1.7 var.m
--- var.m 1997/11/11 10:25:54 1.7
+++ var.m 1997/11/11 10:42:25
@@ -97,6 +97,25 @@
% dump_var prints out a representation of a variable.
:- pred dump_var(var(T)::in(any), io__state::di, io__state::uo) is cc_multi.
+ % var__is_ground/2 can be used to test if a variable is ground.
+ %
+ % Declaratively, is_ground(Var, Result) is true iff
+ % either Result = no or Var = var(Value) and Result = yes(Value);
+ % that is, it is equivalent to the following clauses:
+ %
+ % is_ground(var(Value), yes(Value)).
+ % is_ground(_, no).
+ %
+ % Operationally, is_ground(Var, Result) returns Result = no
+ % if Var is non-ground, and Result = yes(Value) if Var is ground;
+ % that is, execution will select the first clause if the variable
+ % is ground, and the second clause if the variable is non-ground.
+ %
+ % Beware that is_ground is, and must be, `cc_multi';
+ % making it `det' would not be safe.
+
+:- pred is_ground(var(T)::in(any), maybe(T)::out) is cc_multi.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
@@ -320,6 +339,32 @@
Var = free(DelayedGoals),
destructively_update_binding(VarPtr, ground(Value)),
wakeup_delayed_goals(DelayedGoals, Value)
+ ).
+
+:- pragma c_code( is_ground(Var::in(any), Result::out) /* cc_multi */,
+ may_call_mercury,
+"
+ ML_var_is_ground(TypeInfo_for_T, Var, &Result);
+").
+
+:- pred var__rep_is_ground(var_rep(T), maybe(T)).
+:- mode var__rep_is_ground(in(ptr(var_rep_any)), out) is det.
+:- pragma export(var__rep_is_ground(in(ptr(var_rep_any)), out),
+ "ML_var_is_ground").
+var__rep_is_ground(VarPtr, Result) :-
+ VarPtr = alias(Var),
+ (
+ Var = alias(_),
+ var__rep_is_ground(Var, Result)
+ ;
+ Var = ground(Value),
+ Result = yes(Value)
+ ;
+ Var = free,
+ Result = no
+ ;
+ Var = free(_DelayedGoals),
+ Result = no
).
%-----------------------------------------------------------------------------%
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list