[m-rev.] diff: clean up most library modules (part 5)

Ralph Becket rafe at cs.mu.OZ.AU
Mon Mar 15 19:32:43 AEDT 2004


library/*.m:
	Bring these modules up to date with our current style guidelines.
	Use predmode declarations where appropriate. Use state variable syntax
	where appropriate. Reorder arguments where this makes it possible to
	to use state variable syntax.

library/io.m:
	Export some predicates that are duplicated in term_io.m and/or
	parser.m, and give them more expressive names.

library/parser.m:
library/term_io.m:
	Delete the now unnecessary copies of those predicates in these modules.

Zoltan.

Index: term.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.103
diff -u -b -r1.103 term.m
--- term.m	17 Aug 2003 13:30:12 -0000	1.103
+++ term.m	6 Mar 2004 15:24:10 -0000
@@ -21,18 +21,24 @@
 
 %-----------------------------------------------------------------------------%
 
-:- type term(T)		--->	term__functor(
+:- type term(T)
+	--->	term__functor(
 					const,
 					list(term(T)),
 					term__context
 				)
-			;	term__variable(var(T)).
-:- type const		--->	term__atom(string)
+	;	term__variable(
+			var(T)
+		).
+
+:- type const
+	--->	term__atom(string)
 			;	term__integer(int)
 			;	term__string(string)
 			;	term__float(float).
 
-:- type term__context   --->    term__context(string, int).
+:- type term__context
+	--->    term__context(string, int).
 				% file name, line number.
 
 :- type var(T).
@@ -55,9 +61,6 @@
 
 :- type term_to_type_result(T) == term_to_type_result(T, generic).
 
-:- func term__try_term_to_type(term(U)) = term_to_type_result(T, U).
-:- pred term__try_term_to_type(term(U), term_to_type_result(T, U)).
-:- mode term__try_term_to_type(in, out) is det.
 	% term__try_term_to_type(Term, Result):
 	% Try to convert the given term to a ground value of type T.
 	% If successful, return `ok(X)' where X is the converted value.
@@ -71,11 +74,21 @@
 	% offending part of the term was read in from, if available.
 	% ArgContexts specifies the path from the root of the term
 	% to the offending subterm.
+:- func term__try_term_to_type(term(U)) = term_to_type_result(T, U).
+:- pred term__try_term_to_type(term(U)::in, term_to_type_result(T, U)::out)
+	is det.
 
 :- type term_to_type_error(T)
-	--->	type_error(term(T), type_desc, term__context,
-			term_to_type_context)
-	;	mode_error(var(T), term_to_type_context).
+	--->	type_error(
+			term(T),
+			type_desc,
+			term__context,
+			term_to_type_context
+		)
+	;	mode_error(
+			var(T),
+			term_to_type_context
+		).
 
 :- type term_to_type_context == list(term_to_type_arg_context).
 
@@ -86,203 +99,182 @@
 			term__context	% filename & line number
 		).
 
-:- pred term__term_to_type(term(U), T).
-:- mode term__term_to_type(in, out) is semidet.
 	% term_to_type(Term, Type) :- try_term_to_type(Term, ok(Type)).
+:- pred term__term_to_type(term(U)::in, T::out) is semidet.
 
-:- func term__det_term_to_type(term(_)) = T.
-:- pred term__det_term_to_type(term(_), T).
-:- mode term__det_term_to_type(in, out) is det.
 	% like term_to_type, but calls error/1 rather than failing.
+:- func term__det_term_to_type(term(_)) = T.
+:- pred term__det_term_to_type(term(_)::in, T::out) is det.
 
-:- func term__type_to_term(T) = term(_).
-:- pred term__type_to_term(T, term(_)).
-:- mode term__type_to_term(in, out) is det.
 	% converts a value to a term representation of that value
+:- func term__type_to_term(T) = term(_).
+:- pred term__type_to_term(T::in, term(_)::out) is det.
 
-:- func term__univ_to_term(univ) = term(_).
-:- pred term__univ_to_term(univ, term(_)).
-:- mode term__univ_to_term(in, out) is det.
 	% calls term__type_to_term on the value stored in the univ
 	% (as distinct from the univ itself).
+:- func term__univ_to_term(univ) = term(_).
+:- pred term__univ_to_term(univ::in, term(_)::out) is det.
 
 %-----------------------------------------------------------------------------%
 
+	% term__vars(Term, Vars)
+	% Vars is the list of variables contained in Term, in the order
+	% obtained by traversing the term depth first, left-to-right.
 :- func term__vars(term(T)) = list(var(T)).
-:- pred term__vars(term(T), list(var(T))).
-:- mode term__vars(in, out) is det.
-%	term__vars(Term, Vars)
-%		Vars is the list of variables contained in Term, in the order 
-%		obtained by traversing the term depth first, left-to-right.
+:- pred term__vars(term(T)::in, list(var(T))::out) is det.
 
+	% As above, but with an accumulator.
 :- func term__vars_2(term(T), list(var(T))) = list(var(T)).
-:- pred term__vars_2(term(T), list(var(T)), list(var(T))).
-:- mode term__vars_2(in, in, out) is det.
-%		As above, but with an accumulator.
+:- pred term__vars_2(term(T)::in, list(var(T))::in, list(var(T))::out) is det.
 
+	% term__vars_list(TermList, Vars)
+	% Vars is the list of variables contained in TermList, in the order
+	% obtained by traversing the list of terms depth-first, left-to-right.
 :- func term__vars_list(list(term(T))) = list(var(T)).
-:- pred term__vars_list(list(term(T)), list(var(T))).
-:- mode term__vars_list(in, out) is det.
-%	term__vars_list(TermList, Vars)
-%		Vars is the list of variables contained in TermList, in the
-%		order obtained by traversing the list of terms depth-first,
-%		left-to-right.
+:- pred term__vars_list(list(term(T))::in, list(var(T))::out) is det.
 
+	% term__contains_var(Term, Var)
+	% True if Term contains Var. On backtracking returns all the
+	% variables contained in Term.
 :- pred term__contains_var(term(T), var(T)).
 :- mode term__contains_var(in, in) is semidet.
 :- mode term__contains_var(in, out) is nondet.
-%	term__contains_var(Term, Var)
-%		True if Term contains Var. (On backtracking returns all the 
-%		variables contained in Term.)
 
+	% term__contains_var_list(TermList, Var)
+	% True if TermList contains Var. On backtracking returns all the
+	% variables contained in Term.
 :- pred term__contains_var_list(list(term(T)), var(T)).
 :- mode term__contains_var_list(in, in) is semidet.
 :- mode term__contains_var_list(in, out) is nondet.
-%	term__contains_var_list(TermList, Var)
-%		True if TermList contains Var. (On backtracking returns all the 
-%		variables contained in Term.)
 
 :- type substitution(T) == map(var(T), term(T)).
 :- type substitution	== substitution(generic).
 
-:- pred term__unify(term(T), term(T), substitution(T), substitution(T)).
-:- mode term__unify(in, in, in, out) is semidet.
-%	term__unify(Term1, Term2, Bindings0, Bindings)
-%		unify (with occur check) two terms with respect to a set
-%	 	of bindings and possibly update the set of bindings
+	% term__unify(Term1, Term2, Bindings0, Bindings):
+	% Unify (with occur check) two terms with respect to a set of bindings
+	% and possibly update the set of bindings.
+:- pred term__unify(term(T)::in, term(T)::in, substitution(T)::in,
+	substitution(T)::out) is semidet.
 
+	% term__substitute(Term0, Var, Replacement, Term):
+	% Replace all occurrences of Var in Term0 with Replacement,
+	% and return the result in Term.
 :- func term__substitute(term(T), var(T), term(T)) = term(T).
-:- pred term__substitute(term(T), var(T), term(T), term(T)).
-:- mode term__substitute(in, in, in, out) is det.
-%	term__substitute(Term0, Var, Replacement, Term) :
-%		replace all occurrences of Var in Term0 with Replacement,
-%		and return the result in Term.
+:- pred term__substitute(term(T)::in, var(T)::in, term(T)::in, term(T)::out)
+	is det.
 
+	% As above, except for a list of terms rather than a single term.
 :- func term__substitute_list(list(term(T)), var(T), term(T)) = list(term(T)).
-:- pred term__substitute_list(list(term(T)), var(T), term(T), list(term(T))).
-:- mode term__substitute_list(in, in, in, out) is det.
-%		as above, except for a list of terms rather than a single term
-
-:- func term__substitute_corresponding(list(var(T)),
-		list(term(T)), term(T)) = term(T).
-:- pred term__substitute_corresponding(list(var(T)), list(term(T)),
-		term(T), term(T)).
-:- mode term__substitute_corresponding(in, in, in, out) is det.
-%       term__substitute_corresponding(Vars, Repls, Term0, Term).
-%		replace all occurrences of variables in Vars with
-%		the corresponding term in Repls, and return the result in Term.
-%		If Vars contains duplicates, or if Vars is not the same
-%	        length as Repls, the behaviour is undefined and probably
-%		harmful.
+:- pred term__substitute_list(list(term(T))::in, var(T)::in, term(T)::in,
+	list(term(T))::out) is det.
 
+	% term__substitute_corresponding(Vars, Repls, Term0, Term).
+	% Replace all occurrences of variables in Vars with the corresponding
+	% term in Repls, and return the result in Term. If Vars contains
+	% duplicates, or if Vars is not the same length as Repls, the
+	% behaviour is undefined and probably harmful.
+:- func term__substitute_corresponding(list(var(T)), list(term(T)),
+	term(T)) = term(T).
+:- pred term__substitute_corresponding(list(var(T))::in, list(term(T))::in,
+	term(T)::in, term(T)::out) is det.
+
+	% As above, except applies to a list of terms rather than a
+	% single term.
 :- func term__substitute_corresponding_list(list(var(T)),
 		list(term(T)), list(term(T))) = list(term(T)).
-:- pred term__substitute_corresponding_list(list(var(T)), list(term(T)),
-		list(term(T)), list(term(T))).
-:- mode term__substitute_corresponding_list(in, in, in, out) is det.
-%       term__substitute_corresponding_list(Vars, Repls, TermList0, TermList).
-%		As above, except applies to a list of terms rather than a
-%		single term.
+:- pred term__substitute_corresponding_list(list(var(T))::in,
+	list(term(T))::in, list(term(T))::in, list(term(T))::out) is det.
 
+	% term__apply_rec_substitution(Term0, Substitution, Term):
+	% Recursively apply substitution to Term0 until no more substitions
+	% can be applied, and then return the result in Term.
 :- func term__apply_rec_substitution(term(T), substitution(T)) = term(T).
-:- pred term__apply_rec_substitution(term(T), substitution(T), term(T)).
-:- mode term__apply_rec_substitution(in, in, out) is det.
-%	term__apply_rec_substitution(Term0, Substitution, Term) :
-%		recursively apply substitution to Term0 until
-%		no more substitions can be applied, and then
-%		return the result in Term.
+:- pred term__apply_rec_substitution(term(T)::in, substitution(T)::in,
+	term(T)::out) is det.
 
+	% As above, except applies to a list of terms rather than a
+	% single term.
 :- func term__apply_rec_substitution_to_list(list(term(T)),
 		substitution(T)) = list(term(T)).
-:- pred term__apply_rec_substitution_to_list(list(term(T)), substitution(T),
-						list(term(T))).
-:- mode term__apply_rec_substitution_to_list(in, in, out) is det.
+:- pred term__apply_rec_substitution_to_list(list(term(T))::in,
+	substitution(T)::in, list(term(T))::out) is det.
 
+	% term__apply_substitution(Term0, Substitution, Term):
+	% Apply substitution to Term0 and return the result in Term.
 :- func term__apply_substitution(term(T), substitution(T)) = term(T).
-:- pred term__apply_substitution(term(T), substitution(T), term(T)).
-:- mode term__apply_substitution(in, in, out) is det.
-%	term__apply_substitution(Term0, Substitution, Term) :
-%		apply substitution to Term0 and return the result in Term.
+:- pred term__apply_substitution(term(T)::in, substitution(T)::in,
+	term(T)::out) is det.
 
+	% As above, except applies to a list of terms rather than a
+	% single term.
 :- func term__apply_substitution_to_list(list(term(T)),
 		substitution(T)) = list(term(T)).
-:- pred term__apply_substitution_to_list(list(term(T)), substitution(T),
-						list(term(T))).
-:- mode term__apply_substitution_to_list(in, in, out) is det.
-%	term__apply_substitution_to_list(TermList0, Substitution, TermList) :
-%		as above, except for a list of terms rather than a single term
-
-
-:- pred term__occurs(term(T), var(T), substitution(T)).
-:- mode term__occurs(in, in, in) is semidet.
-%	term__occurs(Term0, Var, Substitution) :
-%		true iff Var occurs in the term resulting after
-%		applying Substitution to Term0.
-
-:- pred term__occurs_list(list(term(T)), var(T), substitution(T)).
-:- mode term__occurs_list(in, in, in) is semidet.
-%		as above, except for a list of terms rather than a single term
+:- pred term__apply_substitution_to_list(list(term(T))::in,
+	substitution(T)::in, list(term(T))::out) is det.
 
+	% term__occurs(Term0, Var, Substitution):
+	% True iff Var occurs in the term resulting after applying
+	% Substitution to Term0.
+:- pred term__occurs(term(T)::in, var(T)::in, substitution(T)::in) is semidet.
+
+	% As above, except for a list of terms rather than a single term.
+:- pred term__occurs_list(list(term(T))::in, var(T)::in, substitution(T)::in)
+	is semidet.
+
+	% term__relabel_variable(Term0, OldVar, NewVar, Term):
+	% Replace all occurences of OldVar in Term0 with NewVar and
+	% put the result in Term.
 :- func term__relabel_variable(term(T), var(T), var(T)) = term(T).
-:- pred term__relabel_variable(term(T), var(T), var(T), term(T)).
-:- mode term__relabel_variable(in, in, in, out) is det.
-%	term__relabel_variable(Term0, OldVar, NewVar, Term) :
-%		replace all occurences of OldVar in Term0 with
-%		NewVar and put the result in Term.
+:- pred term__relabel_variable(term(T)::in, var(T)::in, var(T)::in,
+	term(T)::out) is det.
 
+	% As above, except applies to a list of terms rather than a
+	% single term.
+	% XXX the name of the predicate is misleading.
 :- func term__relabel_variables(list(term(T)), var(T), var(T)) = list(term(T)).
-:- pred term__relabel_variables(list(term(T)), var(T), var(T), list(term(T))).
-:- mode term__relabel_variables(in, in, in, out) is det.
-%	term__relabel_variables(Terms0, OldVar, NewVar, Terms) :
-%		same as term__relabel_variable but for a list of terms.
+:- pred term__relabel_variables(list(term(T))::in, var(T)::in, var(T)::in,
+	list(term(T))::out) is det.
 
+	% Same as term__relabel_variable, except relabels multiple variables.
+	% If a variable is not in the map, it is not replaced.
 :- func term__apply_variable_renaming(term(T), map(var(T), var(T))) = term(T).
-:- pred term__apply_variable_renaming(term(T), map(var(T), var(T)), term(T)).
-:- mode term__apply_variable_renaming(in, in, out) is det.
-% 		same as term__relabel_variable, except relabels
-% 		multiple variables. If a variable is not in the
-% 		map, it is not replaced.
+:- pred term__apply_variable_renaming(term(T)::in, map(var(T), var(T))::in,
+	term(T)::out) is det.
 
+	% Applies term__apply_variable_renaming to a list of terms.
 :- func term__apply_variable_renaming_to_list(list(term(T)),
 		map(var(T), var(T))) = list(term(T)).
-:- pred term__apply_variable_renaming_to_list(list(term(T)),
-		map(var(T), var(T)), list(term(T))).
-:- mode term__apply_variable_renaming_to_list(in, in, out) is det.
-%		applies term__apply_variable_renaming to a list of terms.
+:- pred term__apply_variable_renaming_to_list(list(term(T))::in,
+	map(var(T), var(T))::in, list(term(T))::out) is det.
 		
+	% term__is_ground(Term, Bindings) is true iff no variables contained
+	% in Term are non-ground in Bindings.
+:- pred term__is_ground(term(T)::in, substitution(T)::in) is semidet.
 
-:- pred term__is_ground(term(T), substitution(T)).
-:- mode term__is_ground(in, in) is semidet.
-%	term__is_ground(Term, Bindings) is true iff no variables contained
-%		in Term are non-ground in Bindings.
-
-:- pred term__is_ground(term(T)).
-:- mode term__is_ground(in) is semidet.
-%	term__is_ground(Term) is true iff Term contains no variables.
+	% term__is_ground(Term) is true iff Term contains no variables.
+:- pred term__is_ground(term(T)::in) is semidet.
 
 %-----------------------------------------------------------------------------%
 
 	% To manage a supply of variables, use the following 2 predicates.
 	% (We might want to give these a unique mode later.)
 
-
+	% term__init_var_supply(VarSupply):
+	% Returns a fresh var_supply for producing fresh variables.
 :- func term__init_var_supply = var_supply(T).
 :- pred term__init_var_supply(var_supply(T)).
 :- mode term__init_var_supply(out) is det.
 :- mode term__init_var_supply(in) is semidet. % implied
-%	term__init_var_supply(VarSupply) :
-%		returns a fresh var_supply for producing fresh variables.
 
+	% term__create_var(VarSupply0, Variable, VarSupply):
+	% Create a fresh variable (var) and return the updated var_supply.
 :- pred term__create_var(var_supply(T), var(T), var_supply(T)).
 :- mode term__create_var(in, out, out) is det.
-%	term__create_var(VarSupply0, Variable, VarSupply) :
-%		create a fresh variable (var) and return the
-%		updated var_supply.
 
+	% term__var_id(Variable):
+	% Returns a unique number associated with this variable w.r.t.
+	% its originating var_supply.
 :- func term__var_id(var(T)) = int.
-%	term__var_id(Variable) :
-%		returns a unique number associated with this variable w.r.t.
-%		its originating var_supply.
 
 %-----------------------------------------------------------------------------%
 
@@ -292,49 +284,35 @@
 	% sparse_bitset.m.
 :- instance enum(var(_)).
 
+	% Convert a variable to an int.
+	% Different variables map to different ints.
+	% Other than that, the mapping is unspecified.
 :- func term__var_to_int(var(T)) = int.
-:- pred term__var_to_int(var(T), int).
-:- mode term__var_to_int(in, out) is det.
-%		Convert a variable to an int.
-%		Different variables map to different ints.
-%		Other than that, the mapping is unspecified.
+:- pred term__var_to_int(var(T)::in, int::out) is det.
 	
 %-----------------------------------------------------------------------------%
 
 	% Given a term context, return the source line number.
-
-:- pred term__context_line(term__context, int).
-:- mode term__context_line(in, out) is det.
-
+:- pred term__context_line(term__context::in, int::out) is det.
 :- func term__context_line(term__context) = int.
 
 	% Given a term context, return the source file.
-
-:- pred term__context_file(term__context, string).
-:- mode term__context_file(in, out) is det.
-
+:- pred term__context_file(term__context::in, string::out) is det.
 :- func term__context_file(term__context) = string.
 
 	% Used to initialize the term context when reading in
 	% (or otherwise constructing) a term.
-
-:- pred term__context_init(term__context).
-:- mode term__context_init(out) is det.
-
+:- pred term__context_init(term__context::out) is det.
 :- func term__context_init = term__context.
-
-:- pred term__context_init(string, int, term__context).
-:- mode term__context_init(in, in, out) is det.
-
+:- pred term__context_init(string::in, int::in, term__context::out) is det.
 :- func term__context_init(string, int) = term__context.
 
 	% Convert a list of terms which are all vars into a list
 	% of vars.  Abort (call error/1) if the list contains
 	% any non-variables.
 
-:- pred term__term_list_to_var_list(list(term(T)), list(var(T))).
-:- mode term__term_list_to_var_list(in, out) is det.
-
+:- pred term__term_list_to_var_list(list(term(T))::in, list(var(T))::out)
+	is det.
 :- func term__term_list_to_var_list(list(term(T))) = list(var(T)).
 
 	% Convert a list of terms which are all vars into a list
@@ -353,25 +331,18 @@
 	% It is useful because in some instances it doesn't matter what
 	% the type of a term is, and passing it to this predicate will
 	% ground the type avoiding unbound type variable warnings.
-:- pred term__generic_term(term).
-:- mode term__generic_term(in) is det.
+:- pred term__generic_term(term::in) is det.
 
 	% Coerce a term of type `T' into a term of type `U'.
-:- pred term__coerce(term(T), term(U)).
-:- mode term__coerce(in, out) is det.
-
+:- pred term__coerce(term(T)::in, term(U)::out) is det.
 :- func term__coerce(term(T)) = term(U).
 
 	% Coerce a var of type `T' into a var of type `U'.
-:- pred term__coerce_var(var(T), var(U)).
-:- mode term__coerce_var(in, out) is det.
-
+:- pred term__coerce_var(var(T)::in, var(U)::out) is det.
 :- func term__coerce_var(var(T)) = var(U).
 
 	% Coerce a var_supply of type `T' into a var_supply of type `U'.
-:- pred term__coerce_var_supply(var_supply(T), var_supply(U)).
-:- mode term__coerce_var_supply(in, out) is det.
-
+:- pred term__coerce_var_supply(var_supply(T)::in, var_supply(U)::out) is det.
 :- func term__coerce_var_supply(var_supply(T)) = var_supply(U).
 
 %-----------------------------------------------------------------------------%
@@ -391,22 +362,21 @@
 % character type. This also allows an integer where a float
 % is expected.
 
-:- pred term__term_to_type_with_int_instead_of_char(term(U), T).
-:- mode term__term_to_type_with_int_instead_of_char(in, out) is semidet.
+:- pred term__term_to_type_with_int_instead_of_char(term(U)::in, T::out)
+	is semidet.
 
-	% This predidicate is being phased out, because of the problem
-	% mentioned in the "BEWARE:" below.
+	% term__compare(Comparison, Term1, Term2, Bindings) is true iff
+	% there is a binding of Comparison to <, =, or > such
+	% that the binding holds for the two ground terms Term1
+	% and Term2 with respect to the bindings in Bindings.
+	% Fails if Term1 or Term2 is not ground (with respect to
+	% the bindings in Bindings).
+	%
+	% BEWARE: This predicate is being phased out, because the comparison
+	% does *not* ignore the term__contexts in the terms.
 :- pragma obsolete(term__compare/4).
-:- pred term__compare(comparison_result, term(T), term(T), substitution(T)).
-:- mode term__compare(out, in, in, in) is semidet.
-%	term__compare(Comparison, Term1, Term2, Bindings) is true iff
-%		there is a binding of Comparison to <, =, or > such
-%		that the binding holds for the two ground terms Term1
-%		and Term2 with respect to the bindings in Bindings.
-%		Fails if Term1 or Term2 is not ground (with respect to
-%		the bindings in Bindings).
-%		BEWARE: the comparison does not ignore the term__contexts
-%		in the terms.
+:- pred term__compare(comparison_result::out, term(T)::in, term(T)::in,
+	substitution(T)::in) is semidet.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -418,6 +388,7 @@
 
 :- type var_supply(T)
 	--->	var_supply(int).
+
 :- type var(T)
 	--->	var(int).
 
@@ -434,8 +405,8 @@
 	IsAditiTuple = no,
 	term__try_term_to_type(IsAditiTuple, Term, Result).
 
-:- pred term__try_term_to_type(bool, term(U), term_to_type_result(T, U)).
-:- mode term__try_term_to_type(in, in, out) is det.
+:- pred term__try_term_to_type(bool::in, term(U)::in,
+	term_to_type_result(T, U)::out) is det.
 
 term__try_term_to_type(IsAditiTuple, Term, Result) :-
 	term__try_term_to_univ(IsAditiTuple, Term,
@@ -457,8 +428,7 @@
 	term__try_term_to_univ_2(IsAditiTuple, Term, Type, [], Result).
 	
 :- pred term__try_term_to_univ_2(bool::in, term(T)::in, type_desc::in,
-		term_to_type_context::in,
-		term_to_type_result(univ, T)::out) is det.
+	term_to_type_context::in, term_to_type_result(univ, T)::out) is det.
 
 term__try_term_to_univ_2(_, term__variable(Var), _Type, Context,
 		error(mode_error(Var, Context))).
@@ -549,8 +519,8 @@
 	ListType = type_of([Elem]),
 	ArgContext = arg_context(term__atom("array"), 1, TermContext),
 	NewContext = [ArgContext | PrevContext],
-	term__try_term_to_univ_2(IsAditiTuple, ArgList, ListType,
-		NewContext, ArgResult),
+	term__try_term_to_univ_2(IsAditiTuple, ArgList, ListType, NewContext,
+		ArgResult),
 	(
 		ArgResult = ok(ListUniv),
 		has_type(Elem2, ElemType),
@@ -562,8 +532,7 @@
 		ArgResult = error(Error),
 		Result = error(Error)
 	).
-term__term_to_univ_special_case(_, "builtin", "c_pointer", _, _, _, 
-		_, _) :-
+term__term_to_univ_special_case(_, "builtin", "c_pointer", _, _, _, _, _) :-
 	fail.
 term__term_to_univ_special_case(_, "std_util", "univ", [],
 		Term, _, _, Result) :-
@@ -598,14 +567,15 @@
 		list(type_desc)::in, term__const::in, int::in,
 		term_to_type_context::in, term__context::in,
 		term_to_type_result(list(univ), T)::out) is semidet.
+
 term__term_list_to_univ_list(_, [], [], _, _, _, _, ok([])).
 term__term_list_to_univ_list(IsAditiTuple, [ArgTerm|ArgTerms],
 		[Type|Types], Functor, ArgNum, PrevContext,
 		TermContext, Result) :-
 	ArgContext = arg_context(Functor, ArgNum, TermContext),
 	NewContext = [ArgContext | PrevContext],
-	term__try_term_to_univ_2(IsAditiTuple, ArgTerm, Type,
-		NewContext, ArgResult),
+	term__try_term_to_univ_2(IsAditiTuple, ArgTerm, Type, NewContext,
+		ArgResult),
 	(
 		ArgResult = ok(Arg),
 		term__term_list_to_univ_list(IsAditiTuple, ArgTerms, Types,
@@ -625,18 +595,18 @@
 
 :- pred term__find_functor(type_desc::in, string::in, int::in, int::out,
 		list(type_desc)::out) is semidet.
+
 term__find_functor(Type, Functor, Arity, FunctorNumber, ArgTypes) :-
 	N = num_functors(Type),
 	term__find_functor_2(Type, Functor, Arity, N, FunctorNumber, ArgTypes).
         
 :- pred term__find_functor_2(type_desc::in, string::in, int::in, int::in, 
 	int::out, list(type_desc)::out) is semidet.
+
 term__find_functor_2(TypeInfo, Functor, Arity, Num, FunctorNumber, ArgTypes) :-
 	Num >= 0,
 	Num1 = Num - 1,
-	(
-		get_functor(TypeInfo, Num1, Functor, Arity, ArgTypes1)
-	->
+	( get_functor(TypeInfo, Num1, Functor, Arity, ArgTypes1) ->
 		ArgTypes = ArgTypes1,
 		FunctorNumber = Num1
 	;
@@ -648,7 +618,8 @@
 	( term__term_to_type(Term, X1) ->
 		X = X1
 	; \+ term__is_ground(Term) ->
-		error("term__det_term_to_type failed, because the term wasn't ground")
+		error("term__det_term_to_type failed, " ++
+			"because the term wasn't ground")
 	;
 		string__append_list([
 			"term__det_term_to_type failed, due to a type error:\n",
@@ -721,8 +692,7 @@
 			% XXX what operator should we use for type
 			% qualification?
 			[term__functor(term__atom(":"),	 % TYPE_QUAL_OP
-				[ValueTerm, TypeTerm],
-				Context)], Context),
+			[ValueTerm, TypeTerm], Context)], Context),
 	type_info_to_term(Context, univ_type(NestedUniv), TypeTerm),
 	NestedUnivValue = univ_value(NestedUniv),
 	term__type_to_term(NestedUnivValue, ValueTerm).
@@ -737,6 +707,7 @@
 	term__type_to_term(List, ArgsTerm).
 
 :- pred same_type(T::unused, T::unused) is det.
+
 same_type(_, _).
 
 :- pred term__univ_list_to_term_list(list(univ)::in,
@@ -748,8 +719,9 @@
 	term__univ_list_to_term_list(Values, Terms).
 
 % given a type_info, return a term that represents the name of that type.
-:- pred type_info_to_term(term__context::in, type_desc::in,
-		term(T)::out) is det.
+:- pred type_info_to_term(term__context::in, type_desc::in, term(T)::out)
+	is det.
+
 type_info_to_term(Context, TypeInfo, Term) :-
 	type_ctor_and_args(TypeInfo, TypeCtor, ArgTypes),
 	TypeName = type_ctor_name(TypeCtor),
@@ -759,10 +731,9 @@
 	( ModuleName = "builtin" ->
 		Term = term__functor(term__atom(TypeName), ArgTerms, Context)
 	;
-		Term = term__functor(term__atom(":"),
-			[term__functor(term__atom(ModuleName), [], Context),
-			 term__functor(term__atom(TypeName), 
-			 	ArgTerms, Context)], Context)
+		Arg1 = term__functor(term__atom(ModuleName), [], Context),
+		Arg2 = term__functor(term__atom(TypeName), ArgTerms, Context),
+		Term = term__functor(term__atom(":"), [Arg1, Arg2], Context)
 	).
 		
 %-----------------------------------------------------------------------------%
@@ -777,48 +748,37 @@
 term__vars_list(Terms, Vars) :-
 	term__vars_2_list(Terms, [], Vars).
 
-term__vars_2(term__variable(V), Vs, [V|Vs]).
-term__vars_2(term__functor(_,Args,_), Vs0, Vs) :-
-	term__vars_2_list(Args, Vs0, Vs).
-
-:- pred term__vars_2_list(list(term(T)), list(var(T)), list(var(T))).
-:- mode term__vars_2_list(in, in, out) is det.
-
-term__vars_2_list([], Vs, Vs).
-term__vars_2_list([T|Ts], Vs0, Vs) :-
-	term__vars_2_list(Ts, Vs0, Vs1),
-	term__vars_2(T, Vs1, Vs).
+term__vars_2(term__variable(Var), !Vars) :-
+	!:Vars = [Var | !.Vars].
+term__vars_2(term__functor(_, Args, _), !Vars) :-
+	term__vars_2_list(Args, !Vars).
+
+:- pred term__vars_2_list(list(term(T))::in, list(var(T))::in,
+	list(var(T))::out) is det.
+
+term__vars_2_list([], !Vars).
+term__vars_2_list([Term | Terms], !Vars) :-
+	term__vars_2_list(Terms, !Vars),
+	term__vars_2(Term, !Vars).
 
 %-----------------------------------------------------------------------------%
 
 	% term__contains_var(Term, Var) is true if Var occurs in Term.
 
-term__contains_var(term__variable(V), V).
-term__contains_var(term__functor(_, Args, _), V) :-
-	term__contains_var_list(Args, V).
-
-term__contains_var_list([T|_], V) :-
-	term__contains_var(T, V).
-term__contains_var_list([_|Ts], V) :-
-	term__contains_var_list(Ts, V).
+term__contains_var(term__variable(Var), Var).
+term__contains_var(term__functor(_, Args, _), Var) :-
+	term__contains_var_list(Args, Var).
+
+term__contains_var_list([Term | _], Var) :-
+	term__contains_var(Term, Var).
+term__contains_var_list([_ | Terms], Var) :-
+	term__contains_var_list(Terms, Var).
 
 %-----------------------------------------------------------------------------%
 
-	% Access predicates for the term__context data structure.
-
-	% Given a term context, return the source line number.
-
 term__context_line(term__context(_, LineNumber), LineNumber).
-
-	% Given a term context, return the source file.
-
 term__context_file(term__context(FileName, _), FileName).
-
-	% Used to initialize the term context when reading in
-	% (or otherwise constructing) a term.
-
 term__context_init(term__context("", 0)).
-
 term__context_init(File, LineNumber, term__context(File, LineNumber)).
 
 %-----------------------------------------------------------------------------%
@@ -826,87 +786,76 @@
 	% Unify two terms (with occurs check), updating the bindings of
 	% the variables in the terms.  
 
-term__unify(term__variable(X), term__variable(Y), Bindings0, Bindings) :-
-	( %%% if some [BindingOfX]
-		map__search(Bindings0, X, BindingOfX)
-	->
-		( %%% if some [BindingOfY]
-			map__search(Bindings0, Y, BindingOfY)
-		->
+term__unify(term__variable(X), term__variable(Y), !Bindings) :-
+	( map__search(!.Bindings, X, BindingOfX) ->
+		( map__search(!.Bindings, Y, BindingOfY) ->
 			% both X and Y already have bindings - just
 			% unify the terms they are bound to
-			term__unify(BindingOfX, BindingOfY, Bindings0, Bindings)
+			term__unify(BindingOfX, BindingOfY, !Bindings)
 		;
 			% Y is a variable which hasn't been bound yet
-			term__apply_rec_substitution(BindingOfX, Bindings0,
+			term__apply_rec_substitution(BindingOfX, !.Bindings,
 				SubstBindingOfX),
 			( SubstBindingOfX = term__variable(Y) ->
-			 	Bindings = Bindings0
+			 	true
 			;
-				\+ term__occurs(SubstBindingOfX, Y, Bindings0),
-				map__set(Bindings0, Y, SubstBindingOfX,
-					Bindings)
+				\+ term__occurs(SubstBindingOfX, Y,
+					!.Bindings),
+				map__set(!.Bindings, Y, SubstBindingOfX,
+					!:Bindings)
 			)
 		)
 	;
-		( %%% if some [BindingOfY2]
-			map__search(Bindings0, Y, BindingOfY2)
-		->
+		( map__search(!.Bindings, Y, BindingOfY) ->
 			% X is a variable which hasn't been bound yet
-			term__apply_rec_substitution(BindingOfY2, Bindings0,
-				SubstBindingOfY2),
-			( SubstBindingOfY2 = term__variable(X) ->
-				Bindings = Bindings0
-			;
-				\+ term__occurs(SubstBindingOfY2, X, Bindings0),
-				map__set(Bindings0, X, SubstBindingOfY2,
-					Bindings)
+			term__apply_rec_substitution(BindingOfY, !.Bindings,
+				SubstBindingOfY),
+			( SubstBindingOfY = term__variable(X) ->
+				true
+			;
+				\+ term__occurs(SubstBindingOfY, X,
+					!.Bindings),
+				map__set(!.Bindings, X, SubstBindingOfY,
+					!:Bindings)
 			)
 		;
 			% both X and Y are unbound variables -
 			% bind one to the other
 			( X = Y ->
-				Bindings = Bindings0
+				true
 			;
-				map__set(Bindings0, X, term__variable(Y),
-					Bindings)
+				map__set(!.Bindings, X, term__variable(Y),
+					!:Bindings)
 			)
 		)
 	).
 
-term__unify(term__variable(X), term__functor(F, As, C), Bindings0, Bindings) :-
-	( %%% if some [BindingOfX]
-		map__search(Bindings0, X, BindingOfX)
-	->
-		term__unify(BindingOfX, term__functor(F, As, C), Bindings0,
-			Bindings)
+term__unify(term__variable(X), term__functor(F, As, C), !Bindings) :-
+	( map__search(!.Bindings, X, BindingOfX) ->
+		term__unify(BindingOfX, term__functor(F, As, C), !Bindings)
 	;
-		\+ term__occurs_list(As, X, Bindings0),
-		map__set(Bindings0, X, term__functor(F, As, C), Bindings)
+		\+ term__occurs_list(As, X, !.Bindings),
+		map__set(!.Bindings, X, term__functor(F, As, C), !:Bindings)
 	).
 
-term__unify(term__functor(F, As, C), term__variable(X), Bindings0, Bindings) :-
-	( %%% if some [BindingOfX]
-		map__search(Bindings0, X, BindingOfX)
-	->
-		term__unify(term__functor(F, As, C), BindingOfX, Bindings0,
-			Bindings)
+term__unify(term__functor(F, As, C), term__variable(X), !Bindings) :-
+	( map__search(!.Bindings, X, BindingOfX) ->
+		term__unify(term__functor(F, As, C), BindingOfX, !Bindings)
 	;
-		\+ term__occurs_list(As, X, Bindings0),
-		map__set(Bindings0, X, term__functor(F, As, C), Bindings)
+		\+ term__occurs_list(As, X, !.Bindings),
+		map__set(!.Bindings, X, term__functor(F, As, C), !:Bindings)
 	).
 
-term__unify(term__functor(F, AsX, _), term__functor(F, AsY, _)) -->
-	term__unify_list(AsX, AsY).
+term__unify(term__functor(F, AsX, _), term__functor(F, AsY, _), !Bindings) :-
+	term__unify_list(AsX, AsY, !Bindings).
 
-:- pred term__unify_list(list(term(T)), list(term(T)),
-		substitution(T), substitution(T)).
-:- mode term__unify_list(in, in, in, out) is semidet.
+:- pred term__unify_list(list(term(T))::in, list(term(T))::in,
+	substitution(T)::in, substitution(T)::out) is semidet.
 
-term__unify_list([], []) --> [].
-term__unify_list([X | Xs], [Y | Ys]) -->
-	term__unify(X, Y),
-	term__unify_list(Xs, Ys).
+term__unify_list([], [], !Bindings).
+term__unify_list([X | Xs], [Y | Ys], !Bindings) :-
+	term__unify(X, Y, !Bindings),
+	term__unify_list(Xs, Ys, !Bindings).
 
 %-----------------------------------------------------------------------------%
 
@@ -915,9 +864,7 @@
 	% not be mapped by the substitution.)
 
 term__occurs(term__variable(X), Y, Bindings) :-
-	(
-		X = Y
-	->
+	( X = Y ->
 		true
 	;
 		map__search(Bindings, X, BindingOfX),
@@ -927,9 +874,7 @@
 	term__occurs_list(As, Y, Bindings).
 
 term__occurs_list([Term | Terms], Y, Bindings) :-
-	(
-		term__occurs(Term, Y, Bindings)
-	->
+	( term__occurs(Term, Y, Bindings) ->
 		true
 	;
 		term__occurs_list(Terms, Y, Bindings)
@@ -942,9 +887,7 @@
 	%	and return the result in Term.
 
 term__substitute(term__variable(Var), SearchVar, Replacement, Term) :-
-	(
-		Var = SearchVar
-	->
+	( Var = SearchVar ->
 		Term = Replacement
 	;
 		Term = term__variable(Var)
@@ -971,27 +914,22 @@
 	( term__substitute_corresponding_2(Ss, Rs, Subst0, Subst) ->
 		term__apply_substitution_to_list(TermList0, Subst, TermList)
 	;
-		error(
-		  "term__substitute_corresponding_list: different length lists"
-		)
+		error("term__substitute_corresponding_list: " ++
+			"different length lists")
 	).
 
-:- pred term__substitute_corresponding_2(list(var(T)), list(term(T)),
-					substitution(T), substitution(T)).
-:- mode term__substitute_corresponding_2(in, in, in, out) is semidet.
-
-term__substitute_corresponding_2([], [], Subst, Subst).
-term__substitute_corresponding_2([S | Ss], [R | Rs], Subst0, Subst) :-
-	map__set(Subst0, S, R, Subst1),
-	term__substitute_corresponding_2(Ss, Rs, Subst1, Subst).
+:- pred term__substitute_corresponding_2(list(var(T))::in, list(term(T))::in,
+	substitution(T)::in, substitution(T)::out) is semidet.
+
+term__substitute_corresponding_2([], [], !Subst).
+term__substitute_corresponding_2([S | Ss], [R | Rs], !Subst) :-
+	map__set(!.Subst, S, R, !:Subst),
+	term__substitute_corresponding_2(Ss, Rs, !Subst).
 
 %-----------------------------------------------------------------------------%
 
 term__apply_rec_substitution(term__variable(Var), Substitution, Term) :-
-	(
-		%some [Replacement]
-		map__search(Substitution, Var, Replacement)
-	->
+	( map__search(Substitution, Var, Replacement) ->
 		% recursively apply the substition to the replacement
 		term__apply_rec_substitution(Replacement, Substitution, Term)
 	;
@@ -1010,10 +948,7 @@
 %-----------------------------------------------------------------------------%
 
 term__apply_substitution(term__variable(Var), Substitution, Term) :-
-	(
-		%some [Replacement]
-		map__search(Substitution, Var, Replacement)
-	->
+	( map__search(Substitution, Var, Replacement) ->
 		Term = Replacement
 	;
 		Term = term__variable(Var)
@@ -1053,6 +988,7 @@
 
 	% Cast an integer to a var(T), subverting the type-checking.
 :- func unsafe_int_to_var(int) = var(T).
+
 term__unsafe_int_to_var(Var) = var(Var).
 
 %-----------------------------------------------------------------------------%
@@ -1063,9 +999,7 @@
 	term__relabel_variables(Terms0, OldVar, NewVar, Terms).
 term__relabel_variable(term__variable(Var0), OldVar, NewVar,
 				term__variable(Var)) :-
-	(
-		Var0 = OldVar
-	->
+	( Var0 = OldVar ->
 		Var = NewVar
 	;
 		Var = Var0
@@ -1076,15 +1010,12 @@
 	term__relabel_variable(Term0, OldVar, NewVar, Term),
 	term__relabel_variables(Terms0, OldVar, NewVar, Terms).
 
-
 term__apply_variable_renaming(term__functor(Const, Args0, Cont), Renaming,
 				 term__functor(Const, Args, Cont)) :-
 	term__apply_variable_renaming_to_list(Args0, Renaming, Args).
 term__apply_variable_renaming(term__variable(Var0), Renaming,
 				 term__variable(Var)) :-
-	(
-		map__search(Renaming, Var0, NewVar)
-	->
+	( map__search(Renaming, Var0, NewVar) ->
 		Var = NewVar
 	;
 		Var = Var0
@@ -1116,11 +1047,10 @@
 term__is_ground(term__functor(_, Args, _), Bindings) :-
 	term__is_ground_2(Args, Bindings).
 
-:- pred term__is_ground_2(list(term(T)), substitution(T)).
-:- mode term__is_ground_2(in, in) is semidet.
+:- pred term__is_ground_2(list(term(T))::in, substitution(T)::in) is semidet.
 
 term__is_ground_2([], _Bindings).
-term__is_ground_2([Term|Terms], Bindings) :-
+term__is_ground_2([Term | Terms], Bindings) :-
 	term__is_ground(Term, Bindings),
 	term__is_ground_2(Terms, Bindings).
 
@@ -1129,11 +1059,10 @@
 term__is_ground(term__functor(_, Args, _)) :-
 	term__is_ground_2(Args).
 
-:- pred term__is_ground_2(list(term(T))).
-:- mode term__is_ground_2(in) is semidet.
+:- pred term__is_ground_2(list(term(T))::in) is semidet.
 
 term__is_ground_2([]).
-term__is_ground_2([Term|Terms]) :-
+term__is_ground_2([Term | Terms]) :-
 	term__is_ground(Term),
 	term__is_ground_2(Terms).
 
@@ -1256,4 +1185,3 @@
 
 term__coerce_var_supply(VS1) = VS2 :-
 	term__coerce_var_supply(VS1, VS2).
-
Index: term_io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/term_io.m,v
retrieving revision 1.67
diff -u -b -r1.67 term_io.m
--- term_io.m	26 May 2003 09:00:31 -0000	1.67
+++ term_io.m	6 Mar 2004 15:46:38 -0000
@@ -20,121 +20,107 @@
 
 % External interface: exported predicates
 
-/***** not yet implemented
-:- type op_type ---> fx; fy; xf; yf; xfx; xfy; yfx; fxx; fxy; fyx; fyy.
-:- pred term_io__op(int, op_type, string, io__state, io__state).
-:- mode term_io__op(in, in, in, di, uo) is det.
-%	term_io__op(Prec, Type, OpName, IOState0, IOState1).
-%		Define an operator as per Prolog op/3 for future calls to
-%		term_io__read_term.
-
-:- type op_details ---> op(int, op_type, string).
-:- pred term_io__current_ops(list(op_details), io__state, io__state).
-:- mode term_io__current_ops(out, di, uo) is det.
-%		Return a list containing all the current operator definitions.
-%		Does not modify the io__state.
-*****/
+% The following are not yet implemented.
+%
+% :- type op_type ---> fx; fy; xf; yf; xfx; xfy; yfx; fxx; fxy; fyx; fyy.
+%
+% 	% term_io__op(Prec, Type, OpName, !IO):
+% 	% Define an operator as per Prolog op/3 for future calls
+% 	% to term_io__read_term.
+% :- pred term_io__op(int::in, op_type::in, string::in, io::di, io::uo) is det.
+%
+% :- type op_details ---> op(int, op_type, string).
+%
+% 	% Return a list containing all the current operator definitions.
+% 	% Does not modify the io__state.
+% :- pred term_io__current_ops(list(op_details)::out, io::di, io::uo) is det.
 
 :- type read_term(T) ---> eof ; error(string, int) ; term(varset(T), term(T)).
 
 :- type read_term	== read_term(generic).
 
-:- pred term_io__read_term(read_term(T), io__state, io__state).
-:- mode term_io__read_term(out, di, uo) is det.
-%	term_io__read_term(Result, IO0, IO1).
-%		Read a term from standard input. Similar to NU-Prolog
-%		read_term/2, except that resulting term is in the ground
-%		representation. Binds Result to either `eof',
-%		`term(VarSet, Term)', or `error(Message, LineNumber)'.
-
-:- pred term_io__read_term_with_op_table(Ops, read_term(T),
-		io__state, io__state) <= op_table(Ops).
-:- mode term_io__read_term_with_op_table(in, out, di, uo) is det.
-%		As above, except uses the given operator table
-%		instead of the standard Mercury operators.
-
-:- pred term_io__write_term(varset(T), term(T), io__state, io__state).
-:- mode term_io__write_term(in, in, di, uo) is det.
-%		Writes a term to standard output.
-
-:- pred term_io__write_term_with_op_table(Ops, varset(T), term(T),
-			io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_term_with_op_table(in, in, in, di, uo) is det.
-%		As above, except uses the given operator table
-%		instead of the standard Mercury operators.
-
-:- pred term_io__write_term_nl(varset(T), term(T), io__state, io__state).
-:- mode term_io__write_term_nl(in, in, di, uo) is det.
-%		As above, except it appends a period and new-line.
-
-:- pred term_io__write_term_nl_with_op_table(Ops, varset(T), term(T),
-		io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_term_nl_with_op_table(in, in, in, di, uo) is det.
-%		As above, except it appends a period and new-line.
-
-:- pred term_io__write_constant(const, io__state, io__state).
-:- mode term_io__write_constant(in, di, uo) is det.
-%		Writes a constant (integer, float, string, or atom)
-%		to stdout.
+	% term_io__read_term(Result, IO0, IO1).
+	% Read a term from standard input. Similar to NU-Prolog read_term/2,
+	% except that resulting term is in the ground representation.
+	% Binds Result to either `eof', `term(VarSet, Term)', or
+	% `error(Message, LineNumber)'.
+:- pred term_io__read_term(read_term(T)::out, io::di, io::uo) is det.
+
+	% As above, except uses the given operator table instead of
+	% the standard Mercury operators.
+:- pred term_io__read_term_with_op_table(Ops::in, read_term(T)::out,
+	io::di, io::uo) is det <= op_table(Ops).
+
+	% Writes a term to standard output.
+:- pred term_io__write_term(varset(T)::in, term(T)::in, io::di, io::uo) is det.
+
+	% As above, except uses the given operator table instead of the
+	% standard Mercury operators.
+:- pred term_io__write_term_with_op_table(Ops::in, varset(T)::in, term(T)::in,
+	io::di, io::uo) is det <= op_table(Ops).
+
+	% As above, except it appends a period and new-line.
+:- pred term_io__write_term_nl(varset(T)::in, term(T)::in, io::di, io::uo)
+	is det.
+
+	% As above, except it appends a period and new-line.
+:- pred term_io__write_term_nl_with_op_table(Ops::in, varset(T)::in,
+	term(T)::in, io::di, io::uo) is det <= op_table(Ops).
+
+	% Writes a constant (integer, float, string, or atom) to stdout.
+:- pred term_io__write_constant(const::in, io::di, io::uo) is det.
 
-:- func term_io__format_constant(const) = string.
 	% Like term_io__write_constant, but return the result in a string.
+:- func term_io__format_constant(const) = string.
 
-:- pred term_io__write_variable(var(T), varset(T), io__state, io__state).
-:- mode term_io__write_variable(in, in, di, uo) is det.
-%		Writes a variable to stdout.
-
-:- pred term_io__write_variable_with_op_table(Ops, var(T), varset(T),
-		io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_variable_with_op_table(in, in, in, di, uo) is det.
-%		As above, except uses the given operator table
-%		instead of the standard Mercury operators.
+	% Writes a variable to stdout.
+:- pred term_io__write_variable(var(T)::in, varset(T)::in, io::di, io::uo)
+	is det.
+
+	% As above, except uses the given operator table instead of the
+	% standard Mercury operators.
+:- pred term_io__write_variable_with_op_table(Ops::in, var(T)::in,
+	varset(T)::in, io::di, io::uo) is det <= op_table(Ops).
 
-:- pred term_io__quote_string(string, io__state, io__state).
-:- mode term_io__quote_string(in, di, uo) is det.
 	% Given a string S, write S in double-quotes, with characters
 	% escaped if necessary, to stdout.
+:- pred term_io__quote_string(string::in, io::di, io::uo) is det.
 
-:- func term_io__quoted_string(string) = string.
 	% Like term_io__quote_string, but return the result in a string.
+:- func term_io__quoted_string(string) = string.
 
-:- pred term_io__quote_atom(string, io__state, io__state).
-:- mode term_io__quote_atom(in, di, uo) is det.
 	% Given an atom-name A, write A, enclosed in single-quotes if necessary,
 	% with characters escaped if necessary, to stdout.
+:- pred term_io__quote_atom(string::in, io::di, io::uo) is det.
 
-:- func term_io__quoted_atom(string) = string.
 	% Like term_io__quote_atom, but return the result in a string.
+:- func term_io__quoted_atom(string) = string.
 
-:- pred term_io__quote_char(char, io__state, io__state).
-:- mode term_io__quote_char(in, di, uo) is det.
 	% Given a character C, write C in single-quotes,
 	% escaped if necessary, to stdout.
+:- pred term_io__quote_char(char::in, io::di, io::uo) is det.
 
-:- pred term_io__write_escaped_char(char, io__state, io__state).
-:- mode term_io__write_escaped_char(in, di, uo) is det.
 	% Given a character C, write C, escaped if necessary, to stdout.
 	% The character is not enclosed in quotes.
+:- pred term_io__write_escaped_char(char::in, io::di, io::uo) is det.
 
-:- func term_io__escaped_char(char) = string.
 	% Like term_io__write_escaped_char, but return the result in a string.
+:- func term_io__escaped_char(char) = string.
 
-:- pred term_io__write_escaped_string(string, io__state, io__state).
-:- mode term_io__write_escaped_string(in, di, uo) is det.
-	% Given a string S, write S, with characters
-	% escaped if necessary, to stdout.
-	% The string is not enclosed in quotes.
+	% Given a string S, write S, with characters escaped if necessary,
+	% to stdout. The string is not enclosed in quotes.
+:- pred term_io__write_escaped_string(string::in, io::di, io::uo) is det.
 
-:- func term_io__escaped_string(string) = string.
 	% Like term_io__write_escaped_char, but return the result in a string.
+:- func term_io__escaped_string(string) = string.
 
 	% `term_io__quote_single_char' is the old (misleading) name for
 	% `term_io__write_escaped_char'.  Use the latter instead.
 :- pragma obsolete(term_io__quote_single_char/3).
-:- pred term_io__quote_single_char(char, io__state, io__state).
-:- mode term_io__quote_single_char(in, di, uo) is det.
+:- pred term_io__quote_single_char(char::in, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
+
 :- implementation.
 
 % Everything below here is not intended to be part of the public interface,
@@ -149,9 +135,8 @@
 	--->	maybe_adjacent_to_graphic_token
 	;	not_adjacent_to_graphic_token.
 
-:- pred term_io__quote_atom(string, adjacent_to_graphic_token,
-		io__state, io__state).
-:- mode term_io__quote_atom(in, in, di, uo) is det.
+:- pred term_io__quote_atom(string::in, adjacent_to_graphic_token::in,
+	io::di, io::uo) is det.
 
 :- func term_io__quoted_atom(string, adjacent_to_graphic_token) = string.
 
@@ -162,12 +147,12 @@
 :- import_module bool, std_util, require, list, string, int, char.
 :- import_module lexer, parser.
 
-term_io__read_term(Result) -->
-	io__get_op_table(Ops),
-	term_io__read_term_with_op_table(Ops, Result).
+term_io__read_term(Result, !IO) :-
+	io__get_op_table(Ops, !IO),
+	term_io__read_term_with_op_table(Ops, Result, !IO).
 
-term_io__read_term_with_op_table(Ops, Result) -->
-	parser__read_term_with_op_table(Ops, Result).
+term_io__read_term_with_op_table(Ops, Result, !IO) :-
+	parser__read_term_with_op_table(Ops, Result, !IO).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -192,37 +177,31 @@
 	% between the two. At the moment we provide only the first, though
 	% the infrastructure for the second is present in the code.
 
-term_io__write_variable(Variable, VarSet) -->
-	io__get_op_table(Ops),
-	term_io__write_variable_with_op_table(Ops, Variable, VarSet).
-
-term_io__write_variable_with_op_table(Ops, Variable, VarSet) -->
-	term_io__write_variable_2(Ops, Variable, VarSet, 0, _, _).
-
-:- pred term_io__write_variable_2(Ops, var(T), varset(T), int, varset(T), int,
-				io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_variable_2(in, in, in, in, out, out, di, uo) is det.
-
-term_io__write_variable_2(Ops, Id, VarSet0, N0, VarSet, N) -->
-	(
-		{ varset__search_var(VarSet0, Id, Val) }
-	->
-		term_io__write_term_2(Ops, Val, VarSet0, N0, VarSet, N)
-	;
-		{ varset__search_name(VarSet0, Id, Name) }
-	->
-		{ N = N0 },
-		{ VarSet = VarSet0 },
-		io__write_string(Name)
+term_io__write_variable(Variable, VarSet, !IO) :-
+	io__get_op_table(Ops, !IO),
+	term_io__write_variable_with_op_table(Ops, Variable, VarSet, !IO).
+
+term_io__write_variable_with_op_table(Ops, Variable, VarSet, !IO) :-
+	term_io__write_variable_2(Ops, Variable, VarSet, _, 0, _, !IO).
+
+:- pred term_io__write_variable_2(Ops::in, var(T)::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
+
+term_io__write_variable_2(Ops, Id, !VarSet, !N, !IO) :-
+	( varset__search_var(!.VarSet, Id, Val) ->
+		term_io__write_term_2(Ops, Val, !VarSet, !N, !IO)
+	; varset__search_name(!.VarSet, Id, Name) ->
+		io__write_string(Name, !IO)
 	;
 		% XXX problems with name clashes
 
-		{ term__var_to_int(Id, VarNum) },
-		{ string__int_to_string(VarNum, Num) },
-		{ string__append("_", Num, VarName) },
-		{ varset__name_var(VarSet0, Id, VarName, VarSet) },
-		{ N = N0 + 1 },
-		io__write_string(VarName)
+		term__var_to_int(Id, VarNum),
+		string__int_to_string(VarNum, Num),
+		string__append("_", Num, VarName),
+		varset__name_var(!.VarSet, Id, VarName, !:VarSet),
+		!:N = !.N + 1,
+		io__write_string(VarName, !IO)
 	).
 
 %-----------------------------------------------------------------------------%
@@ -231,245 +210,214 @@
 	% use the variable names specified by varset and write _N
 	% for all unnamed variables with N starting at 0.
 
-term_io__write_term(VarSet, Term) -->
-	io__get_op_table(Ops),
-	term_io__write_term_with_op_table(Ops, VarSet, Term).
-
-term_io__write_term_with_op_table(Ops, VarSet, Term) -->
-	term_io__write_term_2(Ops, Term, VarSet, 0, _, _).
-
-:- pred term_io__write_term_2(Ops, term(T), varset(T), int, varset(T), int,
-				io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_term_2(in, in, in, in, out, out, di, uo) is det.
+term_io__write_term(VarSet, Term, !IO) :-
+	io__get_op_table(Ops, !IO),
+	term_io__write_term_with_op_table(Ops, VarSet, Term, !IO).
+
+term_io__write_term_with_op_table(Ops, VarSet, Term, !IO) :-
+	term_io__write_term_2(Ops, Term, VarSet, _, 0, _, !IO).
+
+:- pred term_io__write_term_2(Ops::in, term(T)::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
 
-term_io__write_term_2(Ops, Term, VarSet0, N0, VarSet, N) -->
+term_io__write_term_2(Ops, Term, !VarSet, !N, !IO) :-
 	term_io__write_term_3(Ops, Term, ops__max_priority(Ops) + 1,
-		VarSet0, N0, VarSet, N).
+		!VarSet, !N, !IO).
 
-:- pred term_io__write_arg_term(Ops, term(T), varset(T), int, varset(T), int,
-				io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_arg_term(in, in, in, in, out, out, di, uo) is det.
+:- pred term_io__write_arg_term(Ops::in, term(T)::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
 
-term_io__write_arg_term(Ops, Term, VarSet0, N0, VarSet, N) -->
+term_io__write_arg_term(Ops, Term, !VarSet, !N, !IO) :-
 	term_io__write_term_3(Ops, Term, ops__arg_priority(Ops),
-		VarSet0, N0, VarSet, N).
+		!VarSet, !N, !IO).
 
-:- pred term_io__write_term_3(Ops, term(T), ops__priority, varset(T),
-		int, varset(T), int, io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_term_3(in, in, in, in, in, out, out, di, uo) is det.
+:- pred term_io__write_term_3(Ops::in, term(T)::in, ops__priority::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
 
-term_io__write_term_3(Ops, term__variable(Id), _, VarSet0, N0, VarSet, N) -->
-	term_io__write_variable_2(Ops, Id, VarSet0, N0, VarSet, N).
+term_io__write_term_3(Ops, term__variable(Id), _, !VarSet, !N, !IO) :-
+	term_io__write_variable_2(Ops, Id, !VarSet, !N, !IO).
 term_io__write_term_3(Ops, term__functor(Functor, Args, _), Priority,
-			VarSet0, N0, VarSet, N) -->
+			!VarSet, !N, !IO) :-
 	(
-		{ Functor = term__atom("[|]") },
-		{ Args = [ListHead, ListTail] }
+		Functor = term__atom("[|]"),
+		Args = [ListHead, ListTail]
+	->
+		io__write_char('[', !IO),
+		term_io__write_arg_term(Ops, ListHead, !VarSet, !N, !IO),
+		term_io__write_list_tail(Ops, ListTail, !VarSet, !N, !IO),
+		io__write_char(']', !IO)
+	;
+		Functor = term__atom("[]"),
+		Args = []
+	->
+		io__write_string("[]", !IO)
+	;
+		Functor = term__atom("{}"),
+		Args = [BracedTerm]
+	->
+		io__write_string("{ ", !IO),
+		term_io__write_term_2(Ops, BracedTerm, !VarSet, !N, !IO),
+		io__write_string(" }", !IO)
+	;
+		Functor = term__atom("{}"),
+		Args = [BracedHead | BracedTail]
 	->
-		io__write_char('['),
-		term_io__write_arg_term(Ops, ListHead,
-			VarSet0, N0, VarSet1, N1),
-		term_io__write_list_tail(Ops, ListTail,
-			VarSet1, N1, VarSet, N),
-		io__write_char(']')
-	;
-		{ Functor = term__atom("[]") },
-		{ Args = [] }
-	->
-		io__write_string("[]"),
-		{ N = N0 },
-		{ VarSet = VarSet0 }
-	;
-		{ Functor = term__atom("{}") },
-		{ Args = [BracedTerm] }
-	->
-		io__write_string("{ "),
-		term_io__write_term_2(Ops, BracedTerm, VarSet0, N0, VarSet, N),
-		io__write_string(" }")
-	;
-		{ Functor = term__atom("{}") },
-		{ Args = [BracedHead | BracedTail] }
-	->
-		io__write_char('{'),
-		term_io__write_arg_term(Ops, BracedHead,
-			VarSet0, N0, VarSet1, N1),
-		term_io__write_term_args(Ops, BracedTail,
-			VarSet1, N1, VarSet, N),
-		io__write_char('}')
+		io__write_char('{', !IO),
+		term_io__write_arg_term(Ops, BracedHead, !VarSet, !N, !IO),
+		term_io__write_term_args(Ops, BracedTail, !VarSet, !N, !IO),
+		io__write_char('}', !IO)
 	;
 		% the empty functor '' is used for higher-order syntax:
 		% Var(Arg, ...) gets parsed as ''(Var, Arg).  When writing
 		% it out, we want to use the nice syntax.
-		{ Functor = term__atom("") },
-		{ Args = [term__variable(Var), FirstArg | OtherArgs] }
+		Functor = term__atom(""),
+		Args = [term__variable(Var), FirstArg | OtherArgs]
 	->
-		term_io__write_variable_2(Ops, Var, VarSet0, N0, VarSet1, N1),
-		io__write_char('('),
-		term_io__write_arg_term(Ops, FirstArg,
-			VarSet1, N1, VarSet2, N2),
-		term_io__write_term_args(Ops, OtherArgs,
-			VarSet2, N2, VarSet, N),
-		io__write_char(')')
-	;
-		{ Args = [PrefixArg] },
-		{ Functor = term__atom(OpName) },
-		{ ops__lookup_prefix_op(Ops, OpName, OpPriority, OpAssoc) }
-	->
-		maybe_write_char('(', Priority, OpPriority),
-		term_io__write_constant(Functor),
-		io__write_char(' '),
-		{ adjust_priority(OpPriority, OpAssoc, NewPriority) },
+		term_io__write_variable_2(Ops, Var, !VarSet, !N, !IO),
+		io__write_char('(', !IO),
+		term_io__write_arg_term(Ops, FirstArg, !VarSet, !N, !IO),
+		term_io__write_term_args(Ops, OtherArgs, !VarSet, !N, !IO),
+		io__write_char(')', !IO)
+	;
+		Args = [PrefixArg],
+		Functor = term__atom(OpName),
+		ops__lookup_prefix_op(Ops, OpName, OpPriority, OpAssoc)
+	->
+		maybe_write_paren('(', Priority, OpPriority, !IO),
+		term_io__write_constant(Functor, !IO),
+		io__write_char(' ', !IO),
+		adjust_priority_for_assoc(OpPriority, OpAssoc, NewPriority),
 		term_io__write_term_3(Ops, PrefixArg, NewPriority,
-				VarSet0, N0, VarSet, N),
-		maybe_write_char(')', Priority, OpPriority)
+			!VarSet, !N, !IO),
+		maybe_write_paren(')', Priority, OpPriority, !IO)
 	;
-		{ Args = [PostfixArg] },
-		{ Functor = term__atom(OpName) },
-		{ ops__lookup_postfix_op(Ops, OpName, OpPriority, OpAssoc) }
+		Args = [PostfixArg],
+		Functor = term__atom(OpName),
+		ops__lookup_postfix_op(Ops, OpName, OpPriority, OpAssoc)
 	->
-		maybe_write_char('(', Priority, OpPriority),
-		{ adjust_priority(OpPriority, OpAssoc, NewPriority) },
+		maybe_write_paren('(', Priority, OpPriority, !IO),
+		adjust_priority_for_assoc(OpPriority, OpAssoc, NewPriority),
 		term_io__write_term_3(Ops, PostfixArg, NewPriority,
-				VarSet0, N0, VarSet, N),
-		io__write_char(' '),
-		term_io__write_constant(Functor),
-		maybe_write_char(')', Priority, OpPriority)
-	;
-		{ Args = [Arg1, Arg2] },
-		{ Functor = term__atom(OpName) },
-		{ ops__lookup_infix_op(Ops, OpName,
-			OpPriority, LeftAssoc, RightAssoc) }
+			!VarSet, !N, !IO),
+		io__write_char(' ', !IO),
+		term_io__write_constant(Functor, !IO),
+		maybe_write_paren(')', Priority, OpPriority, !IO)
+	;
+		Args = [Arg1, Arg2],
+		Functor = term__atom(OpName),
+		ops__lookup_infix_op(Ops, OpName, OpPriority,
+			LeftAssoc, RightAssoc)
 	->
-		maybe_write_char('(', Priority, OpPriority),
-		{ adjust_priority(OpPriority, LeftAssoc, LeftPriority) },
+		maybe_write_paren('(', Priority, OpPriority, !IO),
+		adjust_priority_for_assoc(OpPriority, LeftAssoc, LeftPriority),
 		term_io__write_term_3(Ops, Arg1, LeftPriority,
-				VarSet0, N0, VarSet1, N1),
-		( { OpName = "," } ->
-			io__write_string(", ")
-		; { OpName = "." } ->
-				% If the operator is '.'/2 then we must
-				% not put spaces around it (or at the
-				% very least, we should not put spaces
-				% afterwards which would make it appear
-				% as the end-of-term token.)  However,
-				% we do have to quote it if the right
-				% hand side can begin with a digit.
-				%
-			io__write_string(
-				if starts_with_digit(Arg2) then "'.'"
-							   else  "."
-			)
+			!VarSet, !N, !IO),
+		( OpName = "," ->
+			io__write_string(", ", !IO)
+		; OpName = "." ->
+				% If the operator is '.'/2 then we must not
+				% put spaces around it (or at the very least,
+				% we should not put spaces afterwards, which
+				% would make it appear as the end-of-term
+				% token). However, we do have to quote it
+				% if the right hand side can begin with
+				% a digit.
+			( starts_with_digit(Arg2) ->
+				Dot = "'.'"
+			;
+				Dot = "."
+			),
+			io__write_string(Dot, !IO)
 		;
-			io__write_char(' '),
-			term_io__write_constant(Functor),
-			io__write_char(' ')
+			io__write_char(' ', !IO),
+			term_io__write_constant(Functor, !IO),
+			io__write_char(' ', !IO)
 		),
-		{ adjust_priority(OpPriority, RightAssoc, RightPriority) },
+		adjust_priority_for_assoc(OpPriority, RightAssoc,
+			RightPriority),
 		term_io__write_term_3(Ops, Arg2, RightPriority,
-				VarSet1, N1, VarSet, N),
-		maybe_write_char(')', Priority, OpPriority)
+			!VarSet, !N, !IO),
+		maybe_write_paren(')', Priority, OpPriority, !IO)
 	;
-		{ Args = [Arg1, Arg2] },
-		{ Functor = term__atom(OpName) },
-		{ ops__lookup_binary_prefix_op(Ops, OpName,
-			OpPriority, FirstAssoc, SecondAssoc) }
-	->
-		maybe_write_char('(', Priority, OpPriority),
-		term_io__write_constant(Functor),
-		io__write_char(' '),
-		{ adjust_priority(OpPriority, FirstAssoc, FirstPriority) },
+		Args = [Arg1, Arg2],
+		Functor = term__atom(OpName),
+		ops__lookup_binary_prefix_op(Ops, OpName, OpPriority,
+			FirstAssoc, SecondAssoc)
+	->
+		maybe_write_paren('(', Priority, OpPriority, !IO),
+		term_io__write_constant(Functor, !IO),
+		io__write_char(' ', !IO),
+		adjust_priority_for_assoc(OpPriority, FirstAssoc,
+			FirstPriority),
 		term_io__write_term_3(Ops, Arg1, FirstPriority,
-				VarSet0, N0, VarSet1, N1),
-		io__write_char(' '),
-		{ adjust_priority(OpPriority, SecondAssoc, SecondPriority) },
+			!VarSet, !N, !IO),
+		io__write_char(' ', !IO),
+		adjust_priority_for_assoc(OpPriority, SecondAssoc,
+			SecondPriority),
 		term_io__write_term_3(Ops, Arg2, SecondPriority,
-				VarSet1, N1, VarSet, N),
-		maybe_write_char(')', Priority, OpPriority)
+			!VarSet, !N, !IO),
+		maybe_write_paren(')', Priority, OpPriority, !IO)
 	;
 		(
-			{ Args = [] },
-			{ Functor = term__atom(Op) },
-			{ ops__lookup_op(Ops, Op) },
-			{ Priority =< ops__max_priority(Ops) }
-		->
-			io__write_char('('),
-			term_io__write_constant(Functor),
-			io__write_char(')')
+			Args = [],
+			Functor = term__atom(Op),
+			ops__lookup_op(Ops, Op),
+			Priority =< ops__max_priority(Ops)
+		->
+			io__write_char('(', !IO),
+			term_io__write_constant(Functor, !IO),
+			io__write_char(')', !IO)
 		;
 			term_io__write_constant(Functor,
-				maybe_adjacent_to_graphic_token)
+				maybe_adjacent_to_graphic_token, !IO)
 		),
-		(
-			{ Args = [X|Xs] }
-		->
-			io__write_char('('),
-			term_io__write_arg_term(Ops, X,
-				VarSet0, N0, VarSet1, N1),
-			term_io__write_term_args(Ops, Xs,
-				VarSet1, N1, VarSet, N),
-			io__write_char(')')
+		( Args = [X | Xs] ->
+			io__write_char('(', !IO),
+			term_io__write_arg_term(Ops, X, !VarSet, !N, !IO),
+			term_io__write_term_args(Ops, Xs, !VarSet, !N, !IO),
+			io__write_char(')', !IO)
 		;
-			{ N = N0,
-			  VarSet = VarSet0 }
+			true
 		)
 	).
 
-:- pred maybe_write_char(char, ops__priority, ops__priority,
-		io__state, io__state).
-:- mode maybe_write_char(in, in, in, di, uo) is det.
-
-maybe_write_char(Char, Priority, OpPriority) -->
-	( { OpPriority > Priority } ->
-		io__write_char(Char)
-	;
-		[]
-	).
-
-:- pred adjust_priority(ops__priority, ops__assoc, ops__priority).
-:- mode adjust_priority(in, in, out) is det.
-
-adjust_priority(Priority, y, Priority).
-adjust_priority(Priority, x, Priority - 1).
-
-:- pred term_io__write_list_tail(Ops, term(T), varset(T), int, varset(T), int,
-				io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_list_tail(in, in, in, in, out, out, di, uo) is det.
+:- pred term_io__write_list_tail(Ops::in, term(T)::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
 
-term_io__write_list_tail(Ops, Term, VarSet0, N0, VarSet, N) -->
+term_io__write_list_tail(Ops, Term, !VarSet, !N, !IO) :-
 	( 
-		{ Term = term__variable(Id) },
-		{ varset__search_var(VarSet0, Id, Val) }
+		Term = term__variable(Id),
+		varset__search_var(!.VarSet, Id, Val)
 	->
-		term_io__write_list_tail(Ops, Val, VarSet0, N0, VarSet, N)
+		term_io__write_list_tail(Ops, Val, !VarSet, !N, !IO)
 	;
-		{ Term = term__functor(term__atom("[|]"),
-				[ListHead, ListTail], _) }
+		Term = term__functor(term__atom("[|]"),
+			[ListHead, ListTail], _)
 	->
-		io__write_string(", "),
-		term_io__write_arg_term(Ops, ListHead,
-			VarSet0, N0, VarSet1, N1),
-		term_io__write_list_tail(Ops, ListTail, VarSet1, N1, VarSet, N)
+		io__write_string(", ", !IO),
+		term_io__write_arg_term(Ops, ListHead, !VarSet, !N, !IO),
+		term_io__write_list_tail(Ops, ListTail, !VarSet, !N, !IO)
 	;
-		{ Term = term__functor(term__atom("[]"), [], _) }
+		Term = term__functor(term__atom("[]"), [], _)
 	->
-		{ VarSet = VarSet0 },
-		{ N = N0 }
+		true
 	;
-		io__write_string(" | "),
-		term_io__write_term_2(Ops, Term, VarSet0, N0, VarSet, N)
+		io__write_string(" | ", !IO),
+		term_io__write_term_2(Ops, Term, !VarSet, !N, !IO)
 	).
 
 	% Succeeds iff outputting the given term would start with a digit.
 	% (This is a safe, conservative approximation and is used to decide
 	% whether or not to quote infix '.'/2.)
 	%
-:- pred starts_with_digit(term(T)).
-:- mode starts_with_digit(in     ) is semidet.
+:- pred starts_with_digit(term(T)::in) is semidet.
 
 starts_with_digit(functor(integer(_), _, _)).
-
 starts_with_digit(functor(float(_), _, _)).
-
 starts_with_digit(functor(atom(Op), Args, _)) :-
 	(
 		Args = [Arg, _],
@@ -482,34 +430,33 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred term_io__write_term_args(Ops, list(term(T)), varset(T), int,
-		varset(T), int, io__state, io__state) <= op_table(Ops).
-:- mode term_io__write_term_args(in, in, in, in, out, out, di, uo) is det.
+:- pred term_io__write_term_args(Ops::in, list(term(T))::in,
+	varset(T)::in, varset(T)::out, int::in, int::out,
+	io::di, io::uo) is det <= op_table(Ops).
 
 	% write the remaining arguments
-term_io__write_term_args(_, [], VarSet, N, VarSet, N) --> [].
-term_io__write_term_args(Ops, [X|Xs], VarSet0, N0, VarSet, N) -->
-	io__write_string(", "),
-	term_io__write_arg_term(Ops, X, VarSet0, N0, VarSet1, N1),
-	term_io__write_term_args(Ops, Xs, VarSet1, N1, VarSet, N).
+term_io__write_term_args(_, [], !VarSet, !N, !IO).
+term_io__write_term_args(Ops, [X | Xs], !VarSet, !N, !IO) :-
+	io__write_string(", ", !IO),
+	term_io__write_arg_term(Ops, X, !VarSet, !N, !IO),
+	term_io__write_term_args(Ops, Xs, !VarSet, !N, !IO).
 
 %-----------------------------------------------------------------------------%
 
-term_io__write_constant(Const) -->
-	term_io__write_constant(Const, not_adjacent_to_graphic_token).
-
-:- pred term_io__write_constant(const, adjacent_to_graphic_token,
-	io__state, io__state).
-:- mode term_io__write_constant(in, in, di, uo) is det.
-
-term_io__write_constant(term__integer(I), _) -->
-	io__write_int(I).
-term_io__write_constant(term__float(F), _) -->
-	io__write_float(F).
-term_io__write_constant(term__atom(A), NextToGraphicToken) -->
-	term_io__quote_atom(A, NextToGraphicToken).
-term_io__write_constant(term__string(S), _) -->
-	term_io__quote_string(S).
+term_io__write_constant(Const, !IO) :-
+	term_io__write_constant(Const, not_adjacent_to_graphic_token, !IO).
+
+:- pred term_io__write_constant(const::in, adjacent_to_graphic_token::in,
+	io::di, io::uo) is det.
+
+term_io__write_constant(term__integer(I), _, !IO) :-
+	io__write_int(I, !IO).
+term_io__write_constant(term__float(F), _, !IO) :-
+	io__write_float(F, !IO).
+term_io__write_constant(term__atom(A), NextToGraphicToken, !IO) :-
+	term_io__quote_atom(A, NextToGraphicToken, !IO).
+term_io__write_constant(term__string(S), _, !IO) :-
+	term_io__quote_string(S, !IO).
 
 term_io__format_constant(Const) =
 	term_io__format_constant(Const, not_adjacent_to_graphic_token).
@@ -527,25 +474,25 @@
 
 %-----------------------------------------------------------------------------%
 
-term_io__quote_char(C) -->
-	io__write_char(''''),
-	term_io__write_escaped_char(C),
-	io__write_char('''').
+term_io__quote_char(C, !IO) :-
+	io__write_char('''', !IO),
+	term_io__write_escaped_char(C, !IO),
+	io__write_char('''', !IO).
 
-term_io__quote_atom(S) -->
-	term_io__quote_atom(S, not_adjacent_to_graphic_token).
+term_io__quote_atom(S, !IO) :-
+	term_io__quote_atom(S, not_adjacent_to_graphic_token, !IO).
 
 term_io__quoted_atom(S) =
 	term_io__quoted_atom(S, not_adjacent_to_graphic_token).
 
-term_io__quote_atom(S, NextToGraphicToken) -->
-	{ ShouldQuote = should_atom_be_quoted(S, NextToGraphicToken) },
-	( { ShouldQuote = no } ->
-		io__write_string(S)
-	;
-		io__write_char(''''),
-		term_io__write_escaped_string(S),
-		io__write_char('''')
+term_io__quote_atom(S, NextToGraphicToken, !IO) :-
+	ShouldQuote = should_atom_be_quoted(S, NextToGraphicToken),
+	( ShouldQuote = no ->
+		io__write_string(S, !IO)
+	;
+		io__write_char('''', !IO),
+		term_io__write_escaped_string(S, !IO),
+		io__write_char('''', !IO)
 	).
 
 term_io__quoted_atom(S, NextToGraphicToken) = String :-
@@ -577,8 +524,10 @@
 		;
 			% graphic token (6.4.2)
 			string__to_char_list(S, Chars),
-			\+ (  list__member(Char, Chars),
-				\+ lexer__graphic_token_char(Char)),
+			\+ (
+				list__member(Char, Chars),
+				\+ lexer__graphic_token_char(Char)
+			),
 			Chars \= [],
 			%
 			% We need to quote tokens starting with '#',
@@ -614,16 +563,16 @@
 	% compiler/mercury_to_mercury.m; any changes here
 	% may require similar changes there.
 
-term_io__quote_string(S) -->
-	io__write_char('"'),
-	term_io__write_escaped_string(S),
-	io__write_char('"').
+term_io__quote_string(S, !IO) :-
+	io__write_char('"', !IO),
+	term_io__write_escaped_string(S, !IO),
+	io__write_char('"', !IO).
 
 term_io__quoted_string(S) =
 	string__append_list(["""", term_io__escaped_string(S), """"]).
 
-term_io__write_escaped_string(String) -->
-	string__foldl(term_io__write_escaped_char, String).
+term_io__write_escaped_string(String, !IO) :-
+	string__foldl(term_io__write_escaped_char, String, !IO).
 
 term_io__escaped_string(String) =
 	string__foldl(term_io__add_escaped_char, String, "").
@@ -633,22 +582,21 @@
 term_io__add_escaped_char(Char, String0) = String :-
 	String = string__append(String0, string__char_to_string(Char)).
 
-term_io__quote_single_char(Char) -->
-	term_io__write_escaped_char(Char).
+term_io__quote_single_char(Char, !IO) :-
+	term_io__write_escaped_char(Char, !IO).
 
 	% Note: the code here is similar to code in
 	% compiler/mercury_to_mercury.m; any changes here
 	% may require similar changes there.
 
-term_io__write_escaped_char(Char) -->
-	( { mercury_escape_special_char(Char, QuoteChar) } ->
-		io__write_char('\\'),
-		io__write_char(QuoteChar)
-	; { is_mercury_source_char(Char) } ->
-		io__write_char(Char)
+term_io__write_escaped_char(Char, !IO) :-
+	( mercury_escape_special_char(Char, QuoteChar) ->
+		io__write_char('\\', !IO),
+		io__write_char(QuoteChar, !IO)
+	; is_mercury_source_char(Char) ->
+		io__write_char(Char, !IO)
 	;
-		{ mercury_escape_char(Char, String) },
-		io__write_string(String)
+		io__write_string(mercury_escape_char(Char), !IO)
 	).
 
 term_io__escaped_char(Char) = String :-
@@ -658,12 +606,9 @@
 	; is_mercury_source_char(Char) ->
 		String = string__char_to_string(Char)
 	;
-		mercury_escape_char(Char, String)
+		String = mercury_escape_char(Char)
 	).
 
-:- pred mercury_escape_char(char, string).
-:- mode mercury_escape_char(in, out) is det.
-
 	% Convert a character to the corresponding octal escape code.
 	%
 	% We use ISO-Prolog style octal escapes, which are of the form
@@ -674,14 +619,15 @@
 	% compiler/mercury_to_mercury.m; any changes here
 	% may require similar changes there.
 
-mercury_escape_char(Char, EscapeCode) :-
+:- func mercury_escape_char(char) = string.
+
+mercury_escape_char(Char) = EscapeCode :-
 	char__to_int(Char, Int),
 	string__int_to_base_string(Int, 8, OctalString0),
 	string__pad_left(OctalString0, '0', 3, OctalString),
 	EscapeCode = "\\" ++ OctalString ++ "\\".
 
-:- pred is_mercury_source_char(char).
-:- mode is_mercury_source_char(in) is semidet.
+:- pred is_mercury_source_char(char::in) is semidet.
 
 	% Succeed if Char is a character which is allowed in
 	% Mercury string and character literals.
@@ -706,8 +652,7 @@
 	% compiler/mercury_to_mercury.m; any changes here
 	% may require similar changes there.
 
-:- pred is_mercury_punctuation_char(char).
-:- mode is_mercury_punctuation_char(in) is semidet.
+:- pred is_mercury_punctuation_char(char::in) is semidet.
 
 is_mercury_punctuation_char(' ').
 is_mercury_punctuation_char('!').
@@ -754,8 +699,7 @@
 	% compiler/mercury_to_mercury.m; any changes here
 	% may require similar changes there.
 
-:- pred mercury_escape_special_char(char, char).
-:- mode mercury_escape_special_char(in, out) is semidet.
+:- pred mercury_escape_special_char(char::in, char::out) is semidet.
 
 mercury_escape_special_char('''', '''').
 mercury_escape_special_char('"', '"').
@@ -767,13 +711,13 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-term_io__write_term_nl(VarSet, Term) -->
-	io__get_op_table(Ops),
-	term_io__write_term_nl_with_op_table(Ops, VarSet, Term).
-
-term_io__write_term_nl_with_op_table(Ops, VarSet, Term) -->
-	term_io__write_term_with_op_table(Ops, VarSet, Term),
-	io__write_string(".\n").
+term_io__write_term_nl(VarSet, Term, !IO) :-
+	io__get_op_table(Ops, !IO),
+	term_io__write_term_nl_with_op_table(Ops, VarSet, Term, !IO).
+
+term_io__write_term_nl_with_op_table(Ops, VarSet, Term, !IO) :-
+	term_io__write_term_with_op_table(Ops, VarSet, Term, !IO),
+	io__write_string(".\n", !IO).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

----- End forwarded message -----
--------------------------------------------------------------------------
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