[m-rev.] For review: State Variables

Ralph Becket rafe at cs.mu.OZ.AU
Fri Jul 5 10:39:09 AEST 2002


Simon Taylor, Friday, 28 June 2002:
> 
> It would be better to be consistent with the way ordinary quantified
> variables are handled (parse them in prog_io_goal.m and prog_io_dcg.m).

Done:

diff -u make_hlds.m make_hlds.m
--- make_hlds.m	25 Jun 2002 06:45:05 -0000
+++ make_hlds.m	4 Jul 2002 05:03:26 -0000
@@ -4965,8 +4965,8 @@
 	{ set__insert_list(QuantVars, Vars, QuantVars1) },
 	warn_singletons_in_goal(SubGoal, QuantVars1, VarSet, PredCallId, MI).
 
-warn_singletons_in_goal_2(if_then_else(Vars, Cond, Then, Else), GoalInfo,
-				QuantVars, VarSet, PredCallId, MI) -->
+warn_singletons_in_goal_2(if_then_else(Vars, Cond, Then, Else),
+				GoalInfo, QuantVars, VarSet, PredCallId, MI) -->
 	%
 	% warn if any quantified variables do not occur in the condition
 	% or the "then" part of the if-then-else
@@ -5839,23 +5839,40 @@
 	{ finish_local_state_vars(StateVars, Vars, SInfo0, SInfo2, SInfo) },
 	{ goal_info_init(GoalInfo) }.
 
-transform_goal_2(if_then_else(Vars0, A0, B0, C0), Context, VarSet0, Subst,
+transform_goal_2(if_then_else(Vars0, StateVars0, A0, B0, C0), Context,
+		VarSet0, Subst,
 		if_then_else(Vars, A, B, C) - GoalInfo, VarSet,
 		Info0, Info, SInfo0, SInfo) -->
+
 	{ substitute_vars(Vars0, Subst, Vars) },
-	transform_goal(A0, VarSet0, Subst, A,  VarSet1, Info0, Info1,
-		SInfo0, SInfoA),
-	transform_goal(B0, VarSet1, Subst, B1, VarSet2, Info1, Info2,
-		SInfoA, SInfoB),
-	transform_goal(C0, VarSet2, Subst, C1, VarSet3, Info2, Info,
+	{ substitute_vars(StateVars0, Subst, StateVars) },
+
+	{ prepare_for_if_then_else_goal(StateVars, VarSet0, VarSet1,
+		SInfo0, SInfoA0) },
+
+	transform_goal(A0, VarSet1, Subst, A,  VarSet2, Info0, Info1,
+		SInfoA0, SInfoA1),
+
+	{ finish_if_then_else_goal_condition(StateVars,
+		SInfo0, SInfoA1, SInfoA, SInfoB0) },
+
+	transform_goal(B0, VarSet2, Subst, B1, VarSet3, Info1, Info2,
+		SInfoB0, SInfoB1),
+
+	{ finish_if_then_else_goal_then_goal(StateVars,
+		SInfo0, SInfoB1, SInfoB) },
+
+	transform_goal(C0, VarSet3, Subst, C1, VarSet4, Info2, Info,
 		SInfo0, SInfoC),
+
 	{ goal_info_init(GoalInfo) },
+
 	{ finish_if_then_else(Context, GoalInfo, B1, B, C1, C,
-		SInfo0, SInfoA, SInfoB, SInfoC, SInfo, VarSet3, VarSet) }.
+		SInfo0, SInfoA, SInfoB, SInfoC, SInfo, VarSet4, VarSet) }.
 
-transform_goal_2(if_then(Vars0, A0, B0), Context, Subst, VarSet0,
+transform_goal_2(if_then(Vars0, StateVars, A0, B0), Context, Subst, VarSet0,
 		Goal, VarSet, Info0, Info, SInfo0, SInfo) -->
-	transform_goal_2(if_then_else(Vars0, A0, B0, true - Context),
+	transform_goal_2(if_then_else(Vars0, StateVars, A0, B0, true - Context),
 		Context, Subst, VarSet0, Goal, VarSet, Info0, Info,
 		SInfo0, SInfo).
 
@@ -7535,24 +7552,9 @@
 			    ElseTerm]
 		},
 		{ term__coerce(IfTerm0, IfTerm) },
-		{ parse_some_vars_goal(IfTerm, VarSet1, Vars,
-			IfParseTree0, VarSet11) }
+		{ parse_some_vars_goal(IfTerm, VarSet1, Vars, StateVars,
+			IfParseTree, VarSet11) }
 	->
-			% The condition can introduce state variables that
-			% also range over the Then goal.  We need to
-			% preserve these state variables for processing the
-			% Then goal and remove them afterwards.
-
-		{ if IfParseTree0 = some_state_vars(StateVars0, IfParseTree1) -
-					_IfCtxt
-		  then
-		  	StateVars   = StateVars0,
-		  	IfParseTree = IfParseTree1
-		  else
-		  	StateVars   = [],
-			IfParseTree = IfParseTree0
-		},
-
 		{ prepare_for_if_then_else_expr(StateVars, VarSet11, VarSet11a,
 			SInfo1, SInfo2) },
 
@@ -9269,8 +9271,8 @@
 :- mode finish_local_state_vars(in, out, in, in, out) is det.
 
 finish_local_state_vars(StateVars, Vars, SInfoBefore, SInfo0, SInfo) :-
-	Dots   = list__map(map__lookup(SInfo0 ^ dot),   StateVars),
-	Colons = list__map(map__lookup(SInfo0 ^ colon), StateVars),
+	Dots   = svar_mappings(SInfo0 ^ dot  , StateVars),
+	Colons = svar_mappings(SInfo0 ^ colon, StateVars),
 	Vars   = list__sort_and_remove_dups(Dots ++ Colons),
 	SInfo  = (( SInfo0 ^ dot   := del_locals(StateVars,
 							SInfoBefore ^ dot,
@@ -9280,13 +9282,24 @@
 							SInfo0 ^ colon) ).
 
 
+:- func svar_mappings(svar_map, svars) = svars.
+
+svar_mappings(_,   []                    ) = [].
+
+svar_mappings(Map, [StateVar | StateVars]) =
+	( if   Map ^ elem(StateVar) = Var
+	  then [Var | svar_mappings(Map, StateVars)]
+	  else svar_mappings(Map, StateVars)
+	).
+
+
 :- func del_locals(svars, svar_map, svar_map) = svar_map.
 
 del_locals(StateVars, MapBefore, Map) =
 	list__foldl(
 		func(K, M) =
-			( if   MapBefore ^ elem(K) = V
-			  then M ^ elem(K) := V
+			( if   MapBefore ^ elem(K) =  V
+			  then M         ^ elem(K) := V
 			  else map__delete(M, K)
 			),
 		StateVars,
@@ -9595,56 +9608,29 @@
 :- mode compare_svar_names(out, in, in) is det.
 
 compare_svar_names(R, A, B) :-
-	csvns_1(R, 1, A, length(A), B, length(B)).
+	compare(R, int_suffix_of(A), int_suffix_of(B)).
 
 
-	% First find the start of the numbers at the right hand end, if
-	% present.
+	% Find the number suffix at the end of a string as an int.
 	%
-:- pred csvns_1(comparison_result, int, string, int, string, int).
-:- mode csvns_1(out, in, in, in, in, in) is det.
+:- func int_suffix_of(string) = int.
 
-csvns_1(R, I, A, MaxA, B, MaxB) :-
-	( if I < MaxA, I < MaxB then
-		X = A `unsafe_index` (MaxA - I),
-		Y = B `unsafe_index` (MaxB - I),
-		( if is_digit(X), is_digit(Y)      then
-			csvns_1(R, I + 1, A, MaxA, B, MaxB)
-		  else if X = ('_'),   is_digit(Y) then
-		  	R = (<)
-		  else if is_digit(X), Y = ('_')   then
-		  	R = (>)
-		  else if X = ('_'),   Y = ('_')   then
-		  	csvns_2(R, I - 1, A, MaxA, B, MaxB)
-		  else if X = Y                    then
-		  	R = (=)
-		  else
-			error("make_hlds__compare_svar_names: \
-names are not in expected format")
-		)
-	  else
-		error("make_hlds__compare_svar_names: \
-names are not in expected format")
-	).
+int_suffix_of(S) = int_suffix_2(S, length(S) - 1, 1, 0).
 
 
-	% Decide the greater of the two numbers at the right hand end
-	% (both numbers will have the same number of digits.)
+	% int_suffix_2(String, Index, RadixOfIndexDigit, IntSoFar) = IntSuffix
 	%
-:- pred csvns_2(comparison_result, int, string, int, string, int).
-:- mode csvns_2(out, in, in, in, in, in) is det.
+:- func int_suffix_2(string, int, int, int) = int.
 
-csvns_2(R, I, A, MaxA, B, MaxB) :-
-	( if 0 < I then
-		X = A `unsafe_index` (MaxA - I) `with_type` char,
-		Y = B `unsafe_index` (MaxB - I) `with_type` char,
-		compare(RXY, X, Y),
-		(	RXY = (<),	R = (<)
-		;	RXY = (=),	csvns_2(R, I - 1, A, MaxA, B, MaxB)
-		;	RXY = (>),	R = (>)
-		)
+int_suffix_2(S, I, R, N) =
+	( if
+		0 =< I,
+		digit_to_int(S `unsafe_index` I, D),
+		D  < 10
+	  then
+		int_suffix_2(S, I - 1, 10 * R, (R * D) + N)
 	  else
-	  	R = (=)
+	  	N
 	).
 
 %------------------------------------------------------------------------------%
@@ -9704,6 +9690,35 @@
 	  else
 	  	error("make_hlds__finish_call: ctxt is not in_atom")
 	).
+
+%------------------------------------------------------------------------------%
+
+:- pred prepare_for_if_then_else_goal(svars, prog_varset, prog_varset,
+		svar_info, svar_info).
+:- mode prepare_for_if_then_else_goal(in, in, out, in, out) is det.
+
+prepare_for_if_then_else_goal(StateVars, VarSet0, VarSet, SInfo0, SInfo) :-
+	prepare_for_local_state_vars(StateVars, VarSet0, VarSet, SInfo0, SInfo).
+
+%------------------------------------------------------------------------------%
+
+:- pred finish_if_then_else_goal_condition(svars,
+		svar_info, svar_info, svar_info, svar_info).
+:- mode finish_if_then_else_goal_condition(in, in, in, out, out) is det.
+
+finish_if_then_else_goal_condition(StateVars,
+		SInfoBefore, SInfoA0, SInfoA, SInfoB) :-
+	SInfoB = SInfoA0,
+	finish_local_state_vars(StateVars, _, SInfoBefore, SInfoA0, SInfoA).
+
+%------------------------------------------------------------------------------%
+
+:- pred finish_if_then_else_goal_then_goal(svars,
+		svar_info, svar_info, svar_info).
+:- mode finish_if_then_else_goal_then_goal(in, in, in, out) is det.
+
+finish_if_then_else_goal_then_goal(StateVars, SInfoBefore, SInfoB0, SInfoB) :-
+	finish_local_state_vars(StateVars, _, SInfoBefore, SInfoB0, SInfoB).
 
 %------------------------------------------------------------------------------%
 
diff -u mercury_to_mercury.m mercury_to_mercury.m
--- mercury_to_mercury.m	4 Jun 2002 04:08:44 -0000
+++ mercury_to_mercury.m	4 Jul 2002 05:21:14 -0000
@@ -2428,9 +2428,10 @@
 		io__write_string(")")
 	).
 
-mercury_output_goal_2(if_then_else(Vars, A, B, C), VarSet, Indent) -->
+mercury_output_goal_2(if_then_else(Vars, StateVars, A, B, C), VarSet,
+		Indent) -->
 	io__write_string("(if"),
-	mercury_output_some(Vars, VarSet),
+	mercury_output_some(Vars, StateVars, VarSet),
 	{ Indent1 = Indent + 1 },
 	mercury_output_newline(Indent1),
 	mercury_output_goal(A, VarSet, Indent1),
@@ -2445,9 +2446,9 @@
 	mercury_output_newline(Indent),
 	io__write_string(")").
 
-mercury_output_goal_2(if_then(Vars, A, B), VarSet, Indent) -->
+mercury_output_goal_2(if_then(Vars, StateVars, A, B), VarSet, Indent) -->
 	io__write_string("(if"),
-	mercury_output_some(Vars, VarSet),
+	mercury_output_some(Vars, StateVars, VarSet),
 	{ Indent1 = Indent + 1 },
 	mercury_output_newline(Indent1),
 	mercury_output_goal(A, VarSet, Indent1),
@@ -2555,17 +2556,18 @@
 		mercury_output_goal(Goal, VarSet, Indent1)
 	).
 
-:- pred mercury_output_some(list(var(T)), varset(T), io__state, io__state).
-:- mode mercury_output_some(in, in, di, uo) is det.
+:- pred mercury_output_some(list(var(T)), list(var(T)), varset(T),
+		io__state, io__state).
+:- mode mercury_output_some(in, in, in, di, uo) is det.
 
-mercury_output_some(Vars, VarSet) -->
-	(
-		{ Vars = [] }
-	->
-		[]
-	;
+mercury_output_some(Vars, StateVars, VarSet) -->
+	( if { Vars \= [] ; StateVars \= [] } then
 		io__write_string(" some ["),
 		mercury_output_vars(Vars, VarSet, no),
+		( if { Vars \= [], StateVars \= [] } then
+			io__write_string(", "),
+			mercury_output_state_vars(StateVars, VarSet, no)
+		),
 		io__write_string("]")
 	).
 
diff -u module_qual.m module_qual.m
--- module_qual.m	4 Jun 2002 04:08:49 -0000
+++ module_qual.m	4 Jul 2002 05:22:08 -0000
@@ -418,12 +418,12 @@
 	bool__and(SuccessA, SuccessB, Success).
 process_assert(not(G) - _, Symbols, Success) :-
 	process_assert(G, Symbols, Success).
-process_assert(if_then(_, GA, GB) - _, Symbols, Success) :-
+process_assert(if_then(_, _, GA, GB) - _, Symbols, Success) :-
 	process_assert(GA, SymbolsA, SuccessA),
 	process_assert(GB, SymbolsB, SuccessB),
 	list__append(SymbolsA, SymbolsB, Symbols),
 	bool__and(SuccessA, SuccessB, Success).
-process_assert(if_then_else(_, GA, GB, GC) - _, Symbols, Success) :-
+process_assert(if_then_else(_, _, GA, GB, GC) - _, Symbols, Success) :-
 	process_assert(GA, SymbolsA, SuccessA),
 	process_assert(GB, SymbolsB, SuccessB),
 	process_assert(GC, SymbolsC, SuccessC),
diff -u prog_data.m prog_data.m
--- prog_data.m	25 Jun 2002 00:50:18 -0000
+++ prog_data.m	3 Jul 2002 02:15:40 -0000
@@ -706,8 +706,11 @@
 
 	% negation and if-then-else
 	;	not(goal)
-	;	if_then(prog_vars, goal, goal)
-	;	if_then_else(prog_vars, goal, goal, goal)
+	;	if_then(prog_vars, prog_vars, goal, goal)
+				% if_then(SomeVars, StateVars, If, Then)
+	;	if_then_else(prog_vars, prog_vars, goal, goal, goal)
+				% if_then_else(SomeVars, StateVars,
+				% 			If, Then, Else)
 
 	% atomic goals
 	;	call(sym_name, list(prog_term), purity)
diff -u prog_io_dcg.m prog_io_dcg.m
--- prog_io_dcg.m	9 May 2002 08:13:27 -0000
+++ prog_io_dcg.m	4 Jul 2002 05:24:05 -0000
@@ -9,6 +9,11 @@
 %
 % This module handles the parsing of clauses in Definite Clause Grammar
 % notation.
+%
+% XXX This module performs no error checking.
+% XXX It may be an idea to recode this as a state variable transformation:
+% 	roughly		Head --> G1, G2, {G3}, G4.
+% 	becomes		Head(!DCG) :- G1(!DCG), G2(!DCG), G3, G4(!DCG).
 
 :- module parse_tree__prog_io_dcg.
 
@@ -195,13 +200,13 @@
 parse_dcg_goal_2("->", [Cond0, Then0], Context, VarSet0, N0, Var0,
 		Goal, VarSet, N, Var) :-
 	parse_dcg_if_then(Cond0, Then0, Context, VarSet0, N0, Var0,
-		SomeVars, Cond, Then, VarSet, N, Var),
+		SomeVars, StateVars, Cond, Then, VarSet, N, Var),
 	( Var = Var0 ->
-		Goal = if_then(SomeVars, Cond, Then) - Context
+		Goal = if_then(SomeVars, StateVars, Cond, Then) - Context
 	;
 		Unify = unify(term__variable(Var), term__variable(Var0)),
-		Goal = if_then_else(SomeVars, Cond, Then, Unify - Context)
-			- Context
+		Goal = if_then_else(SomeVars, StateVars, Cond, Then,
+					Unify - Context) - Context
 	).
 ******/
 
@@ -210,13 +215,13 @@
 			term__functor(term__atom("then"), [Cond0, Then0], _)
 		], Context, VarSet0, N0, Var0, Goal, VarSet, N, Var) :-
 	parse_dcg_if_then(Cond0, Then0, Context, VarSet0, N0, Var0,
-		SomeVars, Cond, Then, VarSet, N, Var),
+		SomeVars, StateVars, Cond, Then, VarSet, N, Var),
 	( Var = Var0 ->
-		Goal = if_then(SomeVars, Cond, Then) - Context
+		Goal = if_then(SomeVars, StateVars, Cond, Then) - Context
 	;
 		Unify = unify(term__variable(Var), term__variable(Var0), pure),
-		Goal = if_then_else(SomeVars, Cond, Then, Unify - Context)
-			- Context
+		Goal = if_then_else(SomeVars, StateVars, Cond, Then,
+					Unify - Context) - Context
 	).
 
 	% Conjunction.
@@ -377,18 +382,27 @@
 		Disjunct = (Disjunct0, Goal - Context) - Context
 	).
 
-:- pred parse_some_vars_dcg_goal(term, list(prog_var), prog_varset,
-		int, prog_var, goal, prog_varset, int, prog_var).
-:- mode parse_some_vars_dcg_goal(in, out, in, in, in, out, out, out, out)
+:- pred parse_some_vars_dcg_goal(term, list(prog_var), list(prog_var),
+		prog_varset, int, prog_var, goal, prog_varset, int, prog_var).
+:- mode parse_some_vars_dcg_goal(in, out, out, in, in, in, out, out, out, out)
 	is det.
-parse_some_vars_dcg_goal(A0, SomeVars, VarSet0, N0, Var0,
+parse_some_vars_dcg_goal(A0, SomeVars, StateVars, VarSet0, N0, Var0,
 		A, VarSet, N, Var) :-
-	( A0 = term__functor(term__atom("some"), [SomeVars0, A1], _Context) ->
-		term__coerce(SomeVars0, SomeVars1),
-		term__vars(SomeVars1, SomeVars),
+	( A0 = term__functor(term__atom("some"), [QVars0, A1], _Context) ->
+		term__coerce(QVars0, QVars),
+		( if parse_quantifier_vars(QVars, StateVars0, SomeVars0) then
+			SomeVars = SomeVars0,
+			StateVars = StateVars0
+		  else
+				% XXX a hack because we do not do
+				% error checking in this module.
+			term__vars(QVars, SomeVars),
+			StateVars = []
+		),
 		A2 = A1
 	;
 		SomeVars = [],
+		StateVars = [],
 		A2 = A0
 	),
 	parse_dcg_goal(A2, VarSet0, N0, Var0, A, VarSet, N, Var).
@@ -414,14 +428,14 @@
 	% so that the implicit quantification of DCG_2 is correct.
 
 :- pred parse_dcg_if_then(term, term, prog_context, prog_varset, int,
-		prog_var, list(prog_var), goal, goal, prog_varset, int,
-		prog_var).
-:- mode parse_dcg_if_then(in, in, in, in, in, in, out, out, out, out, out,
+		prog_var, list(prog_var), list(prog_var), goal, goal,
+		prog_varset, int, prog_var).
+:- mode parse_dcg_if_then(in, in, in, in, in, in, out, out, out, out, out, out,
 		out) is det.
 
 parse_dcg_if_then(Cond0, Then0, Context, VarSet0, N0, Var0,
-		SomeVars, Cond, Then, VarSet, N, Var) :-
-	parse_some_vars_dcg_goal(Cond0, SomeVars, VarSet0, N0, Var0,
+		SomeVars, StateVars, Cond, Then, VarSet, N, Var) :-
+	parse_some_vars_dcg_goal(Cond0, SomeVars, StateVars, VarSet0, N0, Var0,
 				Cond, VarSet1, N1, Var1),
 	parse_dcg_goal(Then0, VarSet1, N1, Var1, Then1, VarSet2, N2,
 		Var2),
@@ -444,7 +458,7 @@
 parse_dcg_if_then_else(Cond0, Then0, Else0, Context, VarSet0, N0, Var0,
 		Goal, VarSet, N, Var) :-
 	parse_dcg_if_then(Cond0, Then0, Context, VarSet0, N0, Var0,
-		SomeVars, Cond, Then1, VarSet1, N1, VarThen),
+		SomeVars, StateVars, Cond, Then1, VarSet1, N1, VarThen),
 	parse_dcg_goal(Else0, VarSet1, N1, Var0, Else1, VarSet, N,
 		VarElse),
 	( VarThen = Var0, VarElse = Var0 ->
@@ -477,7 +491,7 @@
 		prog_util__rename_in_goal(Then1, VarThen, VarElse, Then),
 		Else = Else1
 	),
-	Goal = if_then_else(SomeVars, Cond, Then, Else) - Context.
+	Goal = if_then_else(SomeVars, StateVars, Cond, Then, Else) - Context.
 
 	% term_list_append_term(ListTerm, Term, Result):
 	% 	if ListTerm is a term representing a proper list, 
diff -u prog_io_goal.m prog_io_goal.m
--- prog_io_goal.m	25 Jun 2002 04:47:46 -0000
+++ prog_io_goal.m	4 Jul 2002 05:26:08 -0000
@@ -22,13 +22,13 @@
 :- mode parse_goal(in, in, out, out) is det.
 
 	% Convert a term, possibly starting with `some [Vars]', into
-	% a list of the quantified variables, and a goal. (If the term
-	% doesn't start with `some [Vars]', we return an empty list of
-	% variables.)
+	% a list of the quantified variables, a list of quantified
+	% state variables, and a goal. (If the term doesn't start
+	% with `some [Vars]', we return empty lists of variables.)
 	% 
-:- pred parse_some_vars_goal(term, prog_varset, list(prog_var),
+:- pred parse_some_vars_goal(term, prog_varset, list(prog_var), list(prog_var),
 		goal, prog_varset).
-:- mode parse_some_vars_goal(in, in, out, out, out) is det.
+:- mode parse_some_vars_goal(in, in, out, out, out, out) is det.
 
 	% parse_lambda_expression/3 converts the first argument to a lambda/2
 	% expression into a list of arguments, a list of their corresponding
@@ -157,7 +157,7 @@
 	Since (A -> B) has different semantics in standard Prolog
 	(A -> B ; fail) than it does in NU-Prolog or Mercury (A -> B ; true),
 	for the moment we'll just disallow it.
-parse_goal_2("->", [A0, B0], V0, if_then(Vars, A, B), V) :-
+parse_goal_2("->", [A0, B0], V0, if_then(Vars, StateVars, A, B), V) :-
 	parse_some_vars_goal(A0, V0, Vars, A, V1),
 	parse_goal(B0, V1, B, V).
 ******/
@@ -171,10 +171,10 @@
 	(
 		A0 = term__functor(term__atom("->"), [X0, Y0], _Context)
 	->
-		parse_some_vars_goal(X0, V0, Vars, X, V1),
+		parse_some_vars_goal(X0, V0, Vars, StateVars, X, V1),
 		parse_goal(Y0, V1, Y, V2),
 		parse_goal(B0, V2, B, V),
-		R = if_then_else(Vars, X, Y, B)
+		R = if_then_else(Vars, StateVars, X, Y, B)
 	;
 		parse_goal(A0, V0, A, V1),
 		parse_goal(B0, V1, B, V),
@@ -184,7 +184,7 @@
 	For consistency we also disallow if-then
 parse_goal_2("if",
 		[term__functor(term__atom("then"), [A0, B0], _)], V0,
-		if_then(Vars, A, B), V) :-
+		if_then(Vars, StateVars, A, B), V) :-
 	parse_some_vars_goal(A0, V0, Vars, A, V1),
 	parse_goal(B0, V1, B, V).
 ****/
@@ -194,8 +194,8 @@
 		    ], _),
 		    C0
 		], V0,
-		if_then_else(Vars, A, B, C), V) :-
-	parse_some_vars_goal(A0, V0, Vars, A, V1),
+		if_then_else(Vars, StateVars, A, B, C), V) :-
+	parse_some_vars_goal(A0, V0, Vars, StateVars, A, V1),
 	parse_goal(B0, V1, B, V2),
 	parse_goal(C0, V2, C, V).
 
@@ -301,19 +301,17 @@
 
 %-----------------------------------------------------------------------------%
 
-parse_some_vars_goal(A0, VarSet0, Vars, A, VarSet) :-
+parse_some_vars_goal(A0, VarSet0, Vars, StateVars, A, VarSet) :-
 	( 
-		A0 = term__functor(term__atom("some"), [QVars, A1], Context),
+		A0 = term__functor(term__atom("some"), [QVars, A1], _Context),
 		parse_quantifier_vars(QVars, StateVars0, Vars0)
 	->
 		list__map(term__coerce_var, StateVars0, StateVars),
 		list__map(term__coerce_var, Vars0,      Vars),
-		parse_goal(A1, VarSet0, A2, VarSet),
-		A = ( if   StateVars \= []
-		      then some_state_vars(StateVars, A2) - Context
-		      else A2 )
+		parse_goal(A1, VarSet0, A, VarSet)
 	;
 		Vars      = [],
+		StateVars = [],
 		parse_goal(A0, VarSet0, A, VarSet)
 	).
 
diff -u prog_util.m prog_util.m
--- prog_util.m	29 Apr 2002 03:24:40 -0000
+++ prog_util.m	4 Jul 2002 05:27:27 -0000
@@ -336,14 +336,19 @@
 		equivalent(GoalA, GoalB)) :-
 	prog_util__rename_in_goal(GoalA0, OldVar, NewVar, GoalA),
 	prog_util__rename_in_goal(GoalB0, OldVar, NewVar, GoalB).
-prog_util__rename_in_goal_expr(if_then(Vars0, Cond0, Then0), OldVar, NewVar,
-		if_then(Vars, Cond, Then)) :-
+prog_util__rename_in_goal_expr(if_then(Vars0, StateVars0, Cond0, Then0),
+		OldVar, NewVar,
+		if_then(Vars, StateVars, Cond, Then)) :-
 	prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
+	prog_util__rename_in_vars(StateVars0, OldVar, NewVar, StateVars),
 	prog_util__rename_in_goal(Cond0, OldVar, NewVar, Cond),
 	prog_util__rename_in_goal(Then0, OldVar, NewVar, Then).
-prog_util__rename_in_goal_expr(if_then_else(Vars0, Cond0, Then0, Else0),
-		OldVar, NewVar, if_then_else(Vars, Cond, Then, Else)) :-
+prog_util__rename_in_goal_expr(
+		if_then_else(Vars0, StateVars0, Cond0, Then0, Else0),
+		OldVar, NewVar,
+		if_then_else(Vars, StateVars, Cond, Then, Else)) :-
 	prog_util__rename_in_vars(Vars0, OldVar, NewVar, Vars),
+	prog_util__rename_in_vars(StateVars0, OldVar, NewVar, StateVars),
 	prog_util__rename_in_goal(Cond0, OldVar, NewVar, Cond),
 	prog_util__rename_in_goal(Then0, OldVar, NewVar, Then),
 	prog_util__rename_in_goal(Else0, OldVar, NewVar, Else).

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list