diff: map__lookup: split error handling into new pred

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jul 14 02:37:18 AEST 1998


library/map.m:
	Split the error handling code from map__lookup into a separate
	predicate map__lookup_error.  The reason for this is two-fold:
	(1) this makes it for the compiler to inline map__lookup
	    without inlining all the error handling code
	(2) it can be handy to be able to set a breakpoint on
	    map__lookup_error.

Index: library/map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/map.m,v
retrieving revision 1.63
diff -u -r1.63 map.m
--- map.m	1998/07/09 07:10:23	1.63
+++ map.m	1998/07/09 09:29:09
@@ -225,28 +225,33 @@
 	( tree234__search(Map, K, V1) ->
 		V = V1
 	;
-		KeyType = type_name(type_of(K)),
-		ValueType = type_name(type_of(V)),
-		functor(K, Functor, Arity),
-		( Arity = 0 ->
-			FunctorStr = Functor
-		;
-			string__int_to_string(Arity, ArityStr),
-			string__append_list([Functor, "/", ArityStr],
-				FunctorStr)
-		),
-		string__append_list(
-			["map__lookup: key not found\n",
-			"\tKey Type: ",
-			KeyType,
-			"\n\tKey Functor: ",
-			FunctorStr,
-			"\n\tValue Type: ",
-			ValueType
-			],
-			ErrorString),
-		error(ErrorString)
+		map__lookup_error(K, V)
 	).
+
+:- pred map__lookup_error(K, V).
+:- mode map__lookup_error(in, unused) is erroneous.
+map__lookup_error(K, V) :-
+	KeyType = type_name(type_of(K)),
+	ValueType = type_name(type_of(V)),
+	functor(K, Functor, Arity),
+	( Arity = 0 ->
+		FunctorStr = Functor
+	;
+		string__int_to_string(Arity, ArityStr),
+		string__append_list([Functor, "/", ArityStr],
+			FunctorStr)
+	),
+	string__append_list(
+		["map__lookup: key not found\n",
+		"\tKey Type: ",
+		KeyType,
+		"\n\tKey Functor: ",
+		FunctorStr,
+		"\n\tValue Type: ",
+		ValueType
+		],
+		ErrorString),
+	error(ErrorString).
 
 map__insert(Map0, K, V, Map) :-
 	tree234__insert(Map0, K, V, Map).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list