[m-rev.] diff: fix another problem with set_unordlist.singleton_set/2

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jan 18 14:47:33 AEDT 2012


There are two possible fixes to this problem: the first is to reorder
the existing mode declarations so that the (out, in) is semidet one
occurs first, while the second (below) is to add a clause for the
(in, in) is semidet mode.  Which do people prefer?  (The second seems
more robust in the case of the module interface changing.)

Branches: main, 11.07

Fix another problem with set_unordlist.singleton_set/2.  The implied
(in, in) is semidet mode did not work correctly.

library/set_unordlist.m:
 	Provide an (in, in) is semidet mode for singleton_set/2 that takes
 	account of the fact that the representation may contain duplicates.

tests/hard_coded/singleton_dups.{m,exp}:
 	Extend this test to cover the (in, in) mode.

Julien.

Index: library/set_unordlist.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_unordlist.m,v
retrieving revision 1.37
diff -u -r1.37 set_unordlist.m
--- library/set_unordlist.m	17 Jan 2012 15:49:45 -0000	1.37
+++ library/set_unordlist.m	18 Jan 2012 03:38:09 -0000
@@ -64,6 +64,7 @@
      %
  :- pred set_unordlist.singleton_set(T, set_unordlist(T)).
  :- mode set_unordlist.singleton_set(in, out) is det.
+:- mode set_unordlist.singleton_set(in, in) is semidet.     % Implied.
  :- mode set_unordlist.singleton_set(out, in) is semidet.

  :- func set_unordlist.make_singleton_set(T) = set_unordlist(T).
@@ -402,6 +403,10 @@
  set_unordlist.singleton_set(X::in, Set::out) :-
      Set = sul([X]).

+set_unordlist.singleton_set(X::in, Set::in) :-
+    Set = sul(Xs),
+    list.sort_and_remove_dups(Xs, [X]).
+
  set_unordlist.singleton_set(X::out, Set::in) :-
      Set = sul(Xs),
      list.sort_and_remove_dups(Xs, [X]).
Index: tests/hard_coded/singleton_dups.exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/singleton_dups.exp,v
retrieving revision 1.1
diff -u -r1.1 singleton_dups.exp
--- tests/hard_coded/singleton_dups.exp	17 Jan 2012 15:49:47 -0000	1.1
+++ tests/hard_coded/singleton_dups.exp	18 Jan 2012 03:39:08 -0000
@@ -1 +1,2 @@
  Singleton with element 1
+(in, in) test passed.
Index: tests/hard_coded/singleton_dups.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/singleton_dups.m,v
retrieving revision 1.1
diff -u -r1.1 singleton_dups.m
--- tests/hard_coded/singleton_dups.m	17 Jan 2012 15:49:47 -0000	1.1
+++ tests/hard_coded/singleton_dups.m	18 Jan 2012 03:30:49 -0000
@@ -24,4 +24,18 @@
             else
              io.write_string("Not a singleton set\n", !IO)
          )
+    ),
+
+    % Check that the implied (in, in) is semidet mode works correctly.
+    % 
+    some [!Set2] (
+        set_unordlist.init(!:Set2),
+        set_unordlist.insert(2, !Set2),
+        set_unordlist.insert(2, !Set2),
+        set_unordlist.insert(2, !Set2),
+        ( if set_unordlist.singleton_set(2, !.Set2) then
+            io.write_string("(in, in) test passed.\n", !IO)
+          else
+            io.write_string("(in, in) test FAILED.\n", !IO)
+        )
      ).

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list