for review: library changes

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jul 9 15:01:59 AEST 1998


Estimated hours taken: 1

Assorted library changes.

NEWS
library/eqvclass.m
	Add eqvclass__same_eqvclass_list to test whether a list
	of elements are equivalent.

library/io.nu.nl
library/sp_lib.nl
	Prolog versions of io__getenv, io__make_temp and io__make_err_msg.
	Remove Prolog versions of io__tmpnam, since they are now
	defined in Mercury using io__make_temp.
	
library/map.m
	Include the functor of the key in the error message
	when map__lookup fails.



Index: NEWS
===================================================================
RCS file: /home/staff/zs/imp/mercury/NEWS,v
retrieving revision 1.107
diff -u -t -u -r1.107 NEWS
--- NEWS	1998/07/03 10:34:50	1.107
+++ NEWS	1998/07/07 00:26:39
@@ -306,8 +306,8 @@
   bag__least_upper_bound/3, bag__remove_list/3, bag__det_remove_list/3,
   det_univ_to_type/2, list__take_upto/3, set__count/2, set_ordlist__count/2,
   store__new_cyclic_mutvar/4, relation__add_values/4,
-  relation__from_assoc_list/2, relation__compose/3,
-  and varset__select/3.
+  relation__from_assoc_list/2, relation__compose/3, varset__select/3
+  and eqvclass__same_eqvclass_list/2.
 
   Also the old relation__to_assoc_list/2 predicate has been renamed as
   relation__to_key_assoc_list/2; there is a new relation__to_assoc_list/2
Index: library/eqvclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/eqvclass.m,v
retrieving revision 1.8
diff -u -t -u -r1.8 eqvclass.m
--- eqvclass.m	1998/01/23 12:33:15	1.8
+++ eqvclass.m	1998/02/06 00:07:49
@@ -61,6 +61,11 @@
 :- pred eqvclass__same_eqvclass(eqvclass(T), T, T).
 :- mode eqvclass__same_eqvclass(in, in, in) is semidet.
 
+        % Test if a list of elements are equivalent.
+
+:- pred eqvclass__same_eqvclass_list(eqvclass(T), list(T)).
+:- mode eqvclass__same_eqvclass_list(in, in) is semidet.
+
         % Return the set of the partitions of the equivalence class.
 
 :- pred eqvclass__partition_set(eqvclass(T), set(set(T))).
@@ -188,6 +193,21 @@
         map__search(ElementMap0, Element1, Id1),
         map__search(ElementMap0, Element2, Id2),
         Id1 = Id2.
+
+eqvclass__same_eqvclass_list(_, []).
+eqvclass__same_eqvclass_list(EqvClass, [Element | Elements]) :-
+        EqvClass = eqvclass(_NextId, _PartitionMap, ElementMap),
+        map__search(ElementMap, Element, Id),
+        eqvclass__same_eqvclass_list_2(ElementMap, Elements, Id).
+
+:- pred eqvclass__same_eqvclass_list_2(map(T, partition_id), 
+                list(T), partition_id).
+:- mode eqvclass__same_eqvclass_list_2(in, in, in) is semidet.
+
+eqvclass__same_eqvclass_list_2(_, [], _).
+eqvclass__same_eqvclass_list_2(ElementMap, [Element | Elements], Id) :-
+        map__search(ElementMap, Element, Id),
+        eqvclass__same_eqvclass_list_2(ElementMap, Elements, Id).
 
 eqvclass__partition_set(EqvClass0, PartitionSet) :-
         eqvclass__partition_ids(EqvClass0, Ids),
Index: library/io.nu.nl
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/io.nu.nl,v
retrieving revision 1.60
diff -u -t -u -r1.60 io.nu.nl
--- io.nu.nl	1998/03/30 13:27:26	1.60
+++ io.nu.nl	1998/07/07 01:00:11
@@ -539,12 +539,7 @@
 
 % The following routines work only under SICStus, not under NU-Prolog.
 
-io__tmpnam_2(Name) -->
-        { use_module(library(system)) }, % for tmpnam/1
-        { tmpnam(Atom) },
-        { name(Atom, Name) }.
-
-io__tmpnam(Dir, Prefix, Name) -->
+io__make_temp(Dir, Prefix, Name) -->
         { use_module(library(system)) }, % for mktemp/2
         { dir__directory_separator(SepChar) },
         { string__char_to_string(SepChar, Sep) },
@@ -552,7 +547,13 @@
         { string__append_list([Dir, Sep, LeftPrefix, "XXXXXX"], TemplateName) },
         { name(TemplateAtom, TemplateName) },
         { mktemp(TemplateAtom, TmpAtom) },
-        { name(TmpAtom, Name) }.
+        { name(TmpAtom, Name) },
+        io__open_output(Name, Res),
+        ( { Res = ok(Stream) } ->       
+                io__close_output(Stream)
+        ;
+                { error("error opening temporary file") }
+        ).
 
 io__rename_file_2(OldName, NewName, Result, ResultStr) -->
         { use_module(library(system)) }, % for rename_file/2
@@ -657,6 +658,11 @@
                 Status = -1
         },
         io__update_state.
+
+io__getenv(Var, Val) -->
+        { getenv(Var, Val) }.
+
+io__make_err_msg(Msg, Msg) --> [].
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: library/map.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/map.m,v
retrieving revision 1.62
diff -u -t -u -r1.62 map.m
--- map.m	1998/03/31 23:16:26	1.62
+++ map.m	1998/07/09 04:54:27
@@ -227,10 +227,20 @@
         ;
                 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
                         ],
Index: library/sp_lib.nl
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/sp_lib.nl,v
retrieving revision 1.25
diff -u -t -u -r1.25 sp_lib.nl
--- sp_lib.nl	1998/03/27 12:33:56	1.25
+++ sp_lib.nl	1998/06/05 02:02:49
@@ -114,6 +114,11 @@
 duplicate(Term, Copy) :-
         copy_term(Term, Copy).
 
+getenv(Var, Val) :-
+        use_module(library(system), []),
+        system:environ(Var, Val0),
+        atom_chars(Val0, Val).
+
 %-----------------------------------------------------------------------------%
 
 % Sheesh - do I really have to define these myself!



More information about the developers mailing list