for review: change to term_io.m

Thomas Charles CONWAY conway at cs.mu.OZ.AU
Wed Nov 11 14:07:36 AEDT 1998


Hi

Fergus, could you please review this.

-- 
Thomas Conway <conway at cs.mu.oz.au> )O+
To a killer whale, otters are like hairy popcorn -- Paul Dayton


This change alters the way `_' variables are printed. Currently they're
printed as _N nubered from zero by their first occurence when printed.
This means that if a term containing such variables is split and printed
using two separate calls to write_term, then the corresponding variables
may be printed differently. This change addresses this problem by using
an integer representation of the variable. This fixes the above problem,
but it will make terms printed as error messages a little harder to read,
for example what was printed:
	t(_0, list(T), _1, map(U, pair(V, W)))
may look like
	t(_23, list(T), _17, map(U, pair(V, W)))

The code for doing the first of these is still in place so that later
we can (if we decide to) add a flag to allow users to choose between
the two.

library/term_io.m:
	change term_io__write_variable_2 to use the variable's number
	for making a name for unnamed variables rather than using a
	counter that is local to the call to write_variable or write_term.

cvs diff: Diffing .
Index: term_io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/term_io.m,v
retrieving revision 1.54
diff -u -r1.54 term_io.m
--- term_io.m	1998/11/09 02:43:57	1.54
+++ term_io.m	1998/11/11 02:57:21
@@ -127,8 +127,24 @@
 %-----------------------------------------------------------------------------%
 
 	% write a variable to standard output.
-	% use the variable names specified by varset and write _N
-	% for all unnamed variables with N starting at 0.
+	%
+	% There are two ways we could choose to write unnamed variables
+	% (ie `_'):
+	%	Convert the variable to an integer representation and write
+	%	`_N' where N is that integer representation. This has the
+	%	advantage that such variables get printed in a cannonical
+	%	way, so rearranging terms containing such variables will
+	%	not effect the way they are numbered (this includes breaking
+	%	up a term and printing the pieces separately).
+	% or
+	%	Number the unnamed variables from 0 and write `_N' where
+	%	N is the number in the sequence of such variables. This has
+	%	the advantage that such variables can be visually scanned
+	%	rather more easily (for example in error messages).
+	%
+	% An ideal solution would be to provide both, and a flag to choose
+	% 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) -->
 	term_io__write_variable_2(Variable, VarSet, 0, _, _).
@@ -151,7 +167,8 @@
 	;
 		% XXX problems with name clashes
 
-		{ string__int_to_string(N0, Num) },
+		{ term__var_to_int(Id, VarNum) },
+		{ string__int_to_string(VarNum, Num) },
 		{ string__append("_", Num, VarName) },
 		{ varset__name_var(VarSet0, Id, VarName, VarSet) },
 		{ N is N0 + 1 },



More information about the developers mailing list