for review: three small changes to the library

Zoltan Somogyi zs at cs.mu.oz.au
Thu Jan 8 18:54:22 AEDT 1998


Fergus, please look at these.

The changes to each file are independent and will be committed separately.

lexer.m:
	Derive the context of a token from the front of the token,
	not its end. This is what you want for strings; for other kinds
	of tokens, it shouldn't make a difference.

rbtree.m:
	Factor out some common code by hand, since we can't yet do it
	automatically on the HLDS.

varset.m:
	Remove an obsolete "sanity" check and its documentation.

Zoltan.

cvs diff: Diffing .
Index: lexer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/lexer.m,v
retrieving revision 1.27
diff -u -u -r1.27 lexer.m
--- lexer.m	1997/10/09 13:43:08	1.27
+++ lexer.m	1998/01/08 06:33:35
@@ -132,8 +132,8 @@
 :- mode lexer__get_token(out, out, di, uo) is det.
 
 lexer__get_token(Token, Context) -->
-	lexer__get_token_1(Token),
-	lexer__get_context(Context).
+	lexer__get_context(Context),
+	lexer__get_token_1(Token).
 
 :- pred lexer__get_context(token_context, io__state, io__state).
 :- mode lexer__get_context(out, di, uo) is det.
Index: rbtree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rbtree.m,v
retrieving revision 1.8
diff -u -u -r1.8 rbtree.m
--- rbtree.m	1997/07/27 15:07:06	1.8
+++ rbtree.m	1998/01/02 09:17:37
@@ -571,22 +571,10 @@
 
 %-----------------------------------------------------------------------------%
 
-rbtree__search(empty, _K, _V) :-
-	fail.
-rbtree__search(red(K0, V0, Left, Right), K, V) :-
-	compare(Result, K, K0),
-	(
-		Result = (=)
-	->
-		V = V0
-	;
-		Result = (<)
-	->
-		rbtree__search(Left, K, V)
-	;
-		rbtree__search(Right, K, V)
-	).
-rbtree__search(black(K0, V0, Left, Right), K, V) :-
+rbtree__search(Tree, K, V) :-
+	( Tree = red(K0, V0, Left, Right)
+	; Tree = black(K0, V0, Left, Right)
+	),
 	compare(Result, K, K0),
 	(
 		Result = (=)
Index: varset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/varset.m,v
retrieving revision 1.55
diff -u -u -r1.55 varset.m
--- varset.m	1997/10/09 13:45:05	1.55
+++ varset.m	1998/01/06 04:15:43
@@ -65,9 +65,6 @@
 :- mode varset__vars(in, out) is det.
 
 	% set the name of a variable
-	% (if there is already a variable with the same name "Foo",
-	% then try naming it "Foo'", or "Foo''", or "Foo'''", etc. until
-	% an unused name is found.)
 :- pred varset__name_var(varset, var, string, varset).
 :- mode varset__name_var(in, in, in, out) is det.
 
@@ -181,7 +178,7 @@
 varset__new_named_var(varset(MaxId0, Names0, Vals), Name, Var,
 		varset(MaxId, Names, Vals)) :-
 	term__create_var(MaxId0, Var, MaxId),
-	varset__name_var_2(Names0, Var, Name, Names).
+	map__set(Names0, Var, Name, Names).
 
 varset__new_vars(Varset0, NumVars, NewVars, Varset) :-
 	varset__new_vars_2(Varset0, NumVars, [], NewVars, Varset).
@@ -241,26 +238,10 @@
 
 %-----------------------------------------------------------------------------%
 
-	% If you attempt to name a variable a name which is already
-	% in use, we append sufficient primes ("'") to make the name unique.
-	% Potential efficiency problem: this means that giving N variables
-	% the same name costs O(N*N) time and space.
-
 varset__name_var(VarSet0, Id, Name, VarSet) :-
 	VarSet0 = varset(MaxId, Names0, Vals),
-	varset__name_var_2(Names0, Id, Name, Names),
+	map__set(Names0, Id, Name, Names),
 	VarSet = varset(MaxId, Names, Vals).
-
-:- pred varset__name_var_2(map(var, string), var, string, map(var, string)).
-:- mode varset__name_var_2(in, in, in, out) is det.
-
-varset__name_var_2(Names0, Id, Name, Names) :-
-	( string__remove_suffix(Name, "'", _) ->
-		error("varset__name_var: name is already primed")
-	;
-		true
-	),
-	map__set(Names0, Id, Name, Names).
 
 %-----------------------------------------------------------------------------%
 



More information about the developers mailing list