[m-rev.] diff: use "init" instead of "new" in standard library

Julien Fischer juliensf at csse.unimelb.edu.au
Mon May 9 02:00:43 AEST 2011


Branches: main

Improve consistency amongst the standard library modules.

library/array2d.m:
library/bitmap.m:
library/hash_table.m:
library/store.m:
library/thread.semaphore.m:
library/version_array.m:
library/version_array2d.m:
library/version_bitmap.m:
library/version_hash_table.m:
library/version_store.m:
 	Use the name "init" for predicates and functions that create new empty
 	data structures instead of the name "new".  (The majority of standard
 	library modules already use the former.)

 	Mark the "new" versions as obsolete.

library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/io.m:
library/thread.mvar.m:
browser/declarative_execution.m:
compiler/make.m:
compiler/make.program_target.m:
ssdb/ssdb.m:
 	Conform to the above changes.

NEWS:
 	Announce the above changes.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.565
diff -u -r1.565 NEWS
--- NEWS	6 May 2011 15:19:32 -0000	1.565
+++ NEWS	8 May 2011 15:47:45 -0000
@@ -58,6 +58,43 @@
    maps: bimap.singleton/2, injection.singleton/2, map.singleton/2,
    rbtree.singleton/2 and tree234.singleton/2 .

+* The following procedures have been added to the standard library:
+
+	array2d.init/3
+	bitmap.init/2
+	hash_table.init/3
+	hash_table.init_default/1
+	store.init/1
+	semaphore.init/1
+	semaphore.init/3
+	version_array.init/2
+	version_array2d.init/3
+	version_bitmap.init/2
+	version_hash_table.init/3
+	version_hash_table.unsafe_init/3
+	version_hash_table.init_default/1
+	version_hash_table.unsafe_init_default/1
+	version_store.init/1
+
+   They replace the following procedures, which are now obsolete and will be
+   removed in a later release:
+
+	array2d.new/3
+	bitmap.new/2
+	hash_table.new/3
+	hash_table.new_default/1
+	store.new/1
+	semaphore.new/1
+	semaphore.new/3
+	version_array.new/2
+	version_array2d.new/3
+	version_bitmap.new/2
+	version_hash_table.new/3
+	version_hash_table.unsafe_new/3
+	version_hash_table.new_default/1
+	version_hash_table.unsafe_new_default/1
+	version_store.new/1
+

  NEWS for Mercury 11.01
  ----------------------
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.68
diff -u -r1.68 declarative_execution.m
--- browser/declarative_execution.m	3 May 2011 04:34:52 -0000	1.68
+++ browser/declarative_execution.m	5 May 2011 04:34:32 -0000
@@ -1008,7 +1008,7 @@
          trace_node(trace_node_id)::out) is det.

  set_trace_node_arg(Node0, FieldNum, Val, Node) :-
-    store.new(S0),
+    store.init(S0),
      store.new_ref(Node0, Ref, S0, S1),
      store.arg_ref(Ref, FieldNum, ArgRef, S1, S2),
      store.set_ref_value(ArgRef, Val, S2, S),
Index: compiler/make.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.66
diff -u -r1.66 make.m
--- compiler/make.m	15 Dec 2010 06:29:43 -0000	1.66
+++ compiler/make.m	8 May 2011 14:07:22 -0000
@@ -330,12 +330,12 @@
          globals.lookup_bool_option(Globals, keep_going, KeepGoing),

          ModuleIndexMap = module_index_map(
-            version_hash_table.new_default(module_name_hash),
+            version_hash_table.init_default(module_name_hash),
              version_array.empty, 0),
          DepIndexMap = dependency_file_index_map(
-            version_hash_table.new_default(dependency_file_hash),
+            version_hash_table.init_default(dependency_file_hash),
              version_array.empty, 0),
-        DepStatusMap = version_hash_table.new_default(dependency_file_hash),
+        DepStatusMap = version_hash_table.init_default(dependency_file_hash),

          % Accept and ignore `.depend' targets. `mmc --make' does not need
          % a separate make depend step. The dependencies for each module
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.112
diff -u -r1.112 make.program_target.m
--- compiler/make.program_target.m	5 May 2011 07:11:50 -0000	1.112
+++ compiler/make.program_target.m	8 May 2011 14:18:43 -0000
@@ -1459,7 +1459,7 @@
      io::di, io::uo) is det.

  install_library_grade(LinkSucceeded0, ModuleName, AllModules, Globals, Grade,
-        Succeeded, Info0, Info, !IO) :-
+        Succeeded, !Info, !IO) :-
      % Only remove grade-dependent files after installing if
      % --use-grade-subdirs is not specified by the user.
      globals.lookup_bool_option(Globals, use_grade_subdirs, UseGradeSubdirs),
@@ -1467,7 +1467,7 @@

      % Set up so that grade-dependent files for the current grade
      % don't overwrite the files for the default grade.
-    OptionArgs0 = Info0 ^ option_args,
+    OptionArgs0 = !.Info ^ option_args,
      OptionArgs = OptionArgs0 ++ ["--grade", Grade, "--use-grade-subdirs"],

      verbose_msg(Globals,
@@ -1477,7 +1477,7 @@
              io.nl(!IO)
          ), !IO),

-    lookup_mmc_options(Globals, Info0 ^ options_variables, MaybeMCFlags, !IO),
+    lookup_mmc_options(Globals, !.Info ^ options_variables, MaybeMCFlags, !IO),
      (
          MaybeMCFlags = yes(MCFlags),
          handle_given_options(MCFlags ++ OptionArgs, _, _, _,
@@ -1491,8 +1491,7 @@
      (
          OptionsErrors = [_ | _],
          usage_errors(OptionsErrors, !IO),
-        Succeeded = no,
-        Info = Info0
+        Succeeded = no
      ;
          OptionsErrors = [],

@@ -1502,13 +1501,13 @@
          % XXX version_hash_table.delete is not working properly so just clear
          % the dependency status cache completely.
          %
-        % StatusMap0 = Info0 ^ dependency_status,
+        % StatusMap0 = !.Info ^ dependency_status,
          % StatusMap = version_hash_table.fold(remove_grade_dependent_targets,
          %     StatusMap0, StatusMap0),
-        StatusMap = version_hash_table.new_default(dependency_file_hash),
+        StatusMap = version_hash_table.init_default(dependency_file_hash),

-        Info1 = Info0 ^ dependency_status := StatusMap,
-        Info2 = Info1 ^ option_args := OptionArgs,
+        !Info ^ dependency_status := StatusMap,
+        !Info ^ option_args := OptionArgs,

          % Building the library in the new grade is done in a separate process
          % to make it easier to stop and clean up on an interrupt.
@@ -1524,7 +1523,7 @@
                              ModuleName, AllModules, MInfo, CleanAfter,
                              GradeSuccess0, !IO)
                      ), GradeSuccess, !IO)
-            ), Cleanup, Succeeded, Info2, Info, !IO)
+            ), Cleanup, Succeeded, !Info, !IO)
      ).

  :- func remove_grade_dependent_targets(dependency_file, dependency_status,
Index: library/array2d.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/array2d.m,v
retrieving revision 1.11
diff -u -r1.11 array2d.m
--- library/array2d.m	8 Aug 2008 05:02:21 -0000	1.11
+++ library/array2d.m	8 May 2011 13:40:10 -0000
@@ -39,24 +39,31 @@
  :- mode array2d_ui == in(array2d).
  :- mode array2d_uo == out(array2d).

+    % init(M, N, X) = array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]])
+    % where each XIJ = X.  An exception is thrown if M < 0 or N < 0.
+    %
+:- func init(int, int, T) = array2d(T).
+:- mode init(in, in, in) = array2d_uo is det.
+ 
+    % new(M, N, X) = array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]])
+    % where each XIJ = X.  An exception is thrown if M < 0 or N < 0.
+    %
+:- pragma obsolete(new/3).
+:- func new(int, int, T ) = array2d(T).
+:- mode new(in,  in,  in) = array2d_uo is det.
+
      % array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]]) constructs a array2d
      % of size M * N, with the special case that bounds(array2d([]), 0, 0).
      %
      % An exception is thrown if the sublists are not all the same length.
      %
  :- func array2d(list(list(T))) = array2d(T).
-:- mode array2d(in           ) = array2d_uo is det.
+:- mode array2d(in) = array2d_uo is det.

      % A synonym for the above.
      %
  :- func from_lists(list(list(T))) = array2d(T).
-:- mode from_lists(in           ) = array2d_uo is det.
-
-    % new(M, N, X) = array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]])
-    % where each XIJ = X.  An exception is thrown if M < 0 or N < 0.
-    %
-:- func new(int, int, T ) = array2d(T).
-:- mode new(in,  in,  in) = array2d_uo is det.
+:- mode from_lists(in) = array2d_uo is det.

      % array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]]) ^ elem(I, J) = X
      % where X is the J+1th element of the I+1th row (that is, indices
@@ -141,10 +148,20 @@

  :- implementation.

+
  %-----------------------------------------------------------------------------%

-array2d(      []      ) = array2d(0, 0, make_empty_array).
+init(M, N, X) =
+    ( if    M >= 0, N >= 0
+      then  array2d(M, N, array.init(M * N, X))
+      else  func_error("array2d.new: bounds must be non-negative")
+    ).
+
+new(M, N, X) = init(M, N, X).

+%-----------------------------------------------------------------------------%
+
+array2d([]) = array2d(0, 0, make_empty_array).
  array2d(Xss @ [Xs | _]) = T :-
      M = length(Xss),
      N = length(Xs),
@@ -158,14 +175,6 @@

  %-----------------------------------------------------------------------------%

-new(M, N, X) =
-    ( if    M >= 0, N >= 0
-      then  array2d(M, N, array.init(M * N, X))
-      else  func_error("array2d.new: bounds must be non-negative")
-    ).
-
-%-----------------------------------------------------------------------------%
-
  bounds(array2d(M, N, _A), M, N).

  %-----------------------------------------------------------------------------%
@@ -219,8 +228,9 @@
            else  lists_2(IJ,     N - 1, N, A, [],                  [Xs | Xss])
          )
        else
-        [Xs | Xss]
-    ).
+         [Xs | Xss]
+     ).

  %-----------------------------------------------------------------------------%
+:- end_module array2d.
  %-----------------------------------------------------------------------------%
Index: library/bit_buffer.read.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bit_buffer.read.m,v
retrieving revision 1.2
diff -u -r1.2 bit_buffer.read.m
--- library/bit_buffer.read.m	30 Dec 2010 11:18:04 -0000	1.2
+++ library/bit_buffer.read.m	5 May 2011 04:21:02 -0000
@@ -224,7 +224,7 @@
      SizeInBits = NumBytes * bits_per_byte,
      ChunkSize = int.max(SizeInBits, bits_per_int),
      BMSize = ChunkSize + bits_per_int,
-    BM = bitmap.new(BMSize, no),
+    BM = bitmap.init(BMSize, no),

      % Start at the end of the buffer to force a fill on the first read.
      %
@@ -233,7 +233,7 @@

  new_bitmap_reader(BM, StartIndex, NumBits) = Buffer :-
      Buffer = read_buffer(new_buffer(BM, StartIndex, NumBits, no,
-                error_stream, error_state)).
+        error_stream, error_state)).

  new_bitmap_reader(BM) = new_bitmap_reader(BM, 0, BM ^ num_bits).

Index: library/bit_buffer.write.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bit_buffer.write.m,v
retrieving revision 1.2
diff -u -r1.2 bit_buffer.write.m
--- library/bit_buffer.write.m	22 Sep 2008 01:23:53 -0000	1.2
+++ library/bit_buffer.write.m	5 May 2011 04:21:46 -0000
@@ -166,12 +166,12 @@
  new(NumBytes, Stream, State) = Buffer :-
      SizeInBits = NumBytes * bits_per_byte,
      Size = int.max(SizeInBits, bits_per_int),
-    BM = bitmap.new(Size + int.bits_per_int, no),
+    BM = bitmap.init(Size + int.bits_per_int, no),
      Buffer = write_buffer(new_buffer(BM, 0, Size, yes, Stream, State)).

  new_bitmap_builder(NumBytes) = Buffer :-
      Size = NumBytes * bits_per_byte,
-    BM = bitmap.new(Size + int.bits_per_int, no),
+    BM = bitmap.init(Size + int.bits_per_int, no),
      Buffer = write_buffer(new_buffer(BM, 0, Size, no,
                  error_stream, error_state)).

@@ -252,7 +252,7 @@

  finalize_to_bitmap(write_buffer(Buffer)) = !:BM :-
      NumBits = num_buffered_bits(write_buffer(Buffer)),
-    !:BM = bitmap.new(NumBits),
+    !:BM = bitmap.init(NumBits),

      % Copy out the filled bitmaps starting at the end of the result bitmap.
      %
@@ -379,7 +379,7 @@
      % bitmap created in `new', so we don't need to use
      % copy_bits here).
      %
-    NewBM0 = bitmap.new(NewSize + int.bits_per_int),
+    NewBM0 = bitmap.init(NewSize + int.bits_per_int),
      Remain = Pos - Size,
      NewPos = Remain,
      NewBM = NewBM0 ^ bits(0, Remain) := OldBM ^ bits(Size, Remain),
Index: library/bitmap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bitmap.m,v
retrieving revision 1.41
diff -u -r1.41 bitmap.m
--- library/bitmap.m	3 Nov 2010 05:56:07 -0000	1.41
+++ library/bitmap.m	5 May 2011 04:19:50 -0000
@@ -70,15 +70,27 @@

  %-----------------------------------------------------------------------------%

+    % init(N, B) creates a bitmap of size N (indexed 0 .. N-1)
+    % setting each bit if B = yes and clearing each bit if B = no.
+    % An exception is thrown if N is negative.
+    %
+:- func init(num_bits::in, bool::in) = (bitmap::bitmap_uo) is det.
+
      % new(N, B) creates a bitmap of size N (indexed 0 .. N-1)
      % setting each bit if B = yes and clearing each bit if B = no.
      % An exception is thrown if N is negative.
      %
+:- pragma obsolete(bitmap.new/2).
  :- func new(num_bits, bool) = bitmap.
  :- mode new(in, in) = bitmap_uo is det.

+    % A synonym for init(N, no).
+    %
+:- func init(num_bits::in) = (bitmap::bitmap_uo) is det.
+
      % Same as new(N, no).
      %
+:- pragma obsolete(bitmap.new/1).
  :- func new(num_bits) = bitmap.
  :- mode new(in) = bitmap_uo is det.

@@ -436,9 +448,9 @@

  %-----------------------------------------------------------------------------%

-new(N) = new(N, no).
+init(N) = init(N, no).

-new(N, B) = BM :-
+init(N, B) = BM :-
      ( if N < 0 then
          throw_bitmap_error("bitmap.new: negative size") = _ : int
        else
@@ -447,11 +459,15 @@
          BM   = clear_filler_bits(BM0)
      ).

+new(N, B) = init(N, B).
+
+new(N) = init(N).
+
  %-----------------------------------------------------------------------------%

  resize(!.BM, NewSize, InitializerBit) = !:BM :-
      ( if NewSize =< 0 then
-        !:BM = new(NewSize, InitializerBit)
+        !:BM = init(NewSize, InitializerBit)
        else
          OldSize = num_bits(!.BM),
          InitializerByte = initializer(InitializerBit),
@@ -459,12 +475,12 @@
          ( if NewSize > OldSize then
              % Fill in the trailing bits in the previous final byte.
              !:BM = set_trailing_bits_in_byte(!.BM, OldSize - 1,
-                        InitializerByte),
+                InitializerByte),
              OldLastByteIndex = byte_index_for_bit(OldSize - 1),
              NewLastByteIndex = byte_index_for_bit(NewSize - 1),
              ( if NewLastByteIndex > OldLastByteIndex then
                  !:BM = initialize_bitmap_bytes(!.BM, OldLastByteIndex + 1,
-                            NewLastByteIndex, InitializerByte)
+                    NewLastByteIndex, InitializerByte)
                else
                  true
              )
@@ -897,7 +913,7 @@

  append_list(BMs) = !:BM :-
      BMSize = list.foldl((func(BM, Size) = Size + BM ^ num_bits), BMs, 0),
-    !:BM = new(BMSize),
+    !:BM = init(BMSize),
      list.foldl2(copy_bitmap_into_place, BMs, 0, _, !BM).

  :- pred copy_bitmap_into_place(bitmap::in, int::in, int::out,
Index: library/hash_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/hash_table.m,v
retrieving revision 1.24
diff -u -r1.24 hash_table.m
--- library/hash_table.m	6 May 2011 15:19:33 -0000	1.24
+++ library/hash_table.m	8 May 2011 13:54:42 -0000
@@ -56,7 +56,7 @@
  :- type hash_pred(K) == ( pred(K, int) ).
  :- inst hash_pred    == ( pred(in, out) is det ).

-    % new(HashPred, N, MaxOccupancy)
+    % init(HashPred, N, MaxOccupancy)
      % constructs a new hash table with initial size 2 ^ N that is
      % doubled whenever MaxOccupancy is achieved; elements are
      % indexed using HashPred.
@@ -68,12 +68,24 @@
      % XXX Values too close to the limits may cause bad things
      % to happen.
      %
+:- func init(hash_pred(K), int, float) = hash_table(K, V).
+:- mode init(in(hash_pred), in, in) = hash_table_uo is det.
+
+    % A synonym for the above.
+    %
+:- pragma obsolete(new/3).
  :- func new(hash_pred(K), int, float) = hash_table(K, V).
  :- mode new(in(hash_pred), in, in) = hash_table_uo is det.

-    % new_default(HashFn) constructs a hash table with default size and
+    % init_default(HashFn) constructs a hash table with default size and
      % occupancy arguments.
      %
+:- func init_default(hash_pred(K)) = hash_table(K, V).
+:- mode init_default(in(hash_pred)) = hash_table_uo is det.
+
+    % A synonym for the above.
+    %
+:- pragma obsolete(new_default/1).
  :- func new_default(hash_pred(K)) = hash_table(K, V).
  :- mode new_default(in(hash_pred)) = hash_table_uo is det.

@@ -253,27 +265,30 @@

  %-----------------------------------------------------------------------------%

-new(HashPred, N, MaxOccupancy) = HT :-
+init(HashPred, N, MaxOccupancy) = HT :-
      (      if N =< 0 then
-            throw(software_error("hash_table.new: N =< 0"))
+            throw(software_error("hash_table.init: N =< 0"))
        else if N >= int.bits_per_int then
              throw(software_error(
-                "hash_table.new: N >= int.bits_per_int"))
+                "hash_table.init: N >= int.bits_per_int"))
        else if MaxOccupancy =< 0.0 then
              throw(software_error(
-                "hash_table.new: MaxOccupancy =< 0.0"))
+                "hash_table.init: MaxOccupancy =< 0.0"))
        else
-            NumBuckets   = 1 << N,
+            NumBuckets = 1 << N,
              MaxOccupants = ceiling_to_int(float(NumBuckets) * MaxOccupancy),
-            Buckets      = init(NumBuckets, ht_nil),
-            HT           = ht(0, MaxOccupants, HashPred, Buckets)
+            Buckets = init(NumBuckets, ht_nil),
+            HT = ht(0, MaxOccupants, HashPred, Buckets)
      ).

+new(HashPred, N, MaxOccupancy) = init(HashPred, N, MaxOccupancy).
+
  %-----------------------------------------------------------------------------%

      % These numbers are picked out of thin air.
      %
-new_default(HashPred) = new(HashPred, 7, 0.9).
+init_default(HashPred) = init(HashPred, 7, 0.9).
+new_default(HashPred) = init(HashPred, 7, 0.9).

  %-----------------------------------------------------------------------------%

@@ -435,7 +450,7 @@
      to_assoc_list_2(T, [K - V | AList]).


-from_assoc_list(HP, AList) = from_assoc_list_2(AList, new_default(HP)).
+from_assoc_list(HP, AList) = from_assoc_list_2(AList, init_default(HP)).

  :- func from_assoc_list_2(assoc_list(K, V)::in,
      hash_table(K, V)::hash_table_di) = (hash_table(K, V)::hash_table_uo)
@@ -683,4 +698,5 @@
      dynamic_cast(X, A `with_type` array(ArgType)).

  %-----------------------------------------------------------------------------%
+:- end_module hash_table.
  %-----------------------------------------------------------------------------%
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.459
diff -u -r1.459 io.m
--- library/io.m	6 May 2011 15:19:33 -0000	1.459
+++ library/io.m	7 May 2011 16:09:18 -0000
@@ -1992,7 +1992,7 @@
      io.binary_input_stream_file_size(Stream, FileSize, !IO),
      ( FileSize >= 0 ->
          some [!BM] (
-            !:BM = bitmap.new(FileSize * bits_per_byte),
+            !:BM = bitmap.init(FileSize * bits_per_byte),
              io.read_bitmap(Stream, 0, FileSize,
                  !BM, BytesRead, ReadResult, !IO),
              (
@@ -2027,7 +2027,7 @@

  io.read_binary_file_as_bitmap_2(Stream, BufferSize, Res, !BMs, !IO) :-
      some [!BM] (
-        !:BM = bitmap.new(BufferSize * bits_per_byte),
+        !:BM = bitmap.init(BufferSize * bits_per_byte),
          io.read_bitmap(0, BufferSize, !BM, NumBytesRead, ReadRes, !IO),
          (
              ReadRes = ok,
Index: library/store.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.72
diff -u -r1.72 store.m
--- library/store.m	8 Oct 2010 01:46:21 -0000	1.72
+++ library/store.m	5 May 2011 04:31:40 -0000
@@ -49,6 +49,11 @@

      % Initialize a new store.
      %
+:- some [S] pred store.init(store(S)::uo) is det.
+
+    % A synonym for the above.
+    %
+:- pragma obsolete(store.new/1).
  :- some [S] pred store.new(store(S)::uo) is det.

  %-----------------------------------------------------------------------------%
@@ -272,6 +277,9 @@
  :- type generic_ref(T, S) ---> ref(private_builtin.ref(T)).

  store.new(S) :-
+    store.init(S).
+
+store.init(S) :-
      store.do_init(S).

  :- some [S] pred store.do_init(store(S)::uo) is det.
Index: library/thread.mvar.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/thread.mvar.m,v
retrieving revision 1.2
diff -u -r1.2 thread.mvar.m
--- library/thread.mvar.m	12 Apr 2007 04:31:09 -0000	1.2
+++ library/thread.mvar.m	5 May 2011 04:28:29 -0000
@@ -70,8 +70,8 @@

  :- pragma promise_pure(mvar.init/3).
  mvar.init(mvar(Full, Empty, Ref), !IO) :-
-    semaphore.new(Full, !IO),
-    semaphore.new(Empty, !IO),
+    semaphore.init(Full, !IO),
+    semaphore.init(Empty, !IO),
      impure new_mutvar0(Ref),
      semaphore.signal(Empty, !IO).   % Initially a mvar starts empty.

Index: library/thread.semaphore.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/thread.semaphore.m,v
retrieving revision 1.21
diff -u -r1.21 thread.semaphore.m
--- library/thread.semaphore.m	13 Apr 2011 13:19:41 -0000	1.21
+++ library/thread.semaphore.m	5 May 2011 04:29:32 -0000
@@ -28,14 +28,23 @@

  :- type semaphore.

-    % new(Sem, !IO) creates a new semaphore `Sem' with its counter
+    % init(Sem, !IO) creates a new semaphore `Sem' with its counter
      % initialized to 0.
      %
+:- pred semaphore.init(semaphore::out, io::di, io::uo) is det.
+
+    % A synonym for the above.
+    %
+:- pragma obsolete(semaphore.new/3).
  :- pred semaphore.new(semaphore::out, io::di, io::uo) is det.

-    % new(Count, Sem) creates a new semaphore `Sem' with its counter
-    % initialized to Count.
+    % Returns a new semaphore `Sem' with its counter initialized to Count.
+    %
+:- func semaphore.init(int::in) = (semaphore::uo) is det.
+
+    % A synonym for the above.
      %
+:- pragma obsolete(semaphore.new/1).
  :- func semaphore.new(int::in) = (semaphore::uo) is det.

      % wait(Sem, !IO) blocks until the counter associated with `Sem'
@@ -107,10 +116,15 @@
  %-----------------------------------------------------------------------------%

  new(Semaphore, !IO) :-
-    Semaphore = new(0).
+    init(Semaphore, !IO).
+
+new(Count) = init(Count).
+
+init(Semaphore, !IO) :-
+    Semaphore = init(0).

  :- pragma foreign_proc("C",
-    new(Count::in) = (Semaphore::uo),
+    init(Count::in) = (Semaphore::uo),
      [promise_pure, will_not_call_mercury, thread_safe],
  "
      MR_Word         sem_mem;
@@ -142,7 +156,7 @@
  ").

  :- pragma foreign_proc("C#",
-    new(Count::in) = (Semaphore::uo),
+    init(Count::in) = (Semaphore::uo),
      [promise_pure, will_not_call_mercury, thread_safe],
  "
      Semaphore = new thread__semaphore.ML_Semaphore();
@@ -150,7 +164,7 @@
  ").

  :- pragma foreign_proc("Java",
-    new(Count::in) = (Semaphore::uo),
+    init(Count::in) = (Semaphore::uo),
      [promise_pure, will_not_call_mercury, thread_safe],
  "
      Semaphore = new java.util.concurrent.Semaphore(Count);
Index: library/version_array.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_array.m,v
retrieving revision 1.31
diff -u -r1.31 version_array.m
--- library/version_array.m	18 Nov 2010 07:39:07 -0000	1.31
+++ library/version_array.m	5 May 2011 04:07:31 -0000
@@ -43,13 +43,14 @@
      %
  :- func empty = version_array(T).

-    % new(N, X) returns an array of size N with each item initialised to X.
+    % init(N, X returns an array fo size N with each itme initialised to X.
      %
-:- func new(int, T) = version_array(T).
+:- func init(int, T) = version_array(T).

-    % A synonym for new/2.
+    % new(N, X) returns an array of size N with each item initialised to X.
      %
-:- func init(int, T) = version_array(T).
+:- pragma obsolete(new/2).
+:- func new(int, T) = version_array(T).

      % Same as empty/0 except the resulting version_array is not thread safe.
      %
@@ -211,14 +212,14 @@

  %-----------------------------------------------------------------------------%

-init(N, X) = version_array.new(N, X).
+new(N, X) = version_array.init(N, X).

  %-----------------------------------------------------------------------------%

  version_array([]) = version_array.empty.

  version_array([X | Xs]) =
-    version_array_2(1, Xs, version_array.new(1 + length(Xs), X)).
+    version_array_2(1, Xs, version_array.init(1 + length(Xs), X)).

  :- func version_array_2(int, list(T), version_array(T)) = version_array(T).

@@ -548,7 +549,7 @@
  ").

  :- pragma foreign_proc("C",
-    version_array.new(N::in, X::in) = (VA::out),
+    version_array.init(N::in, X::in) = (VA::out),
      [will_not_call_mercury, promise_pure, will_not_modify_trail,
          does_not_affect_liveness, may_not_duplicate],
  "
Index: library/version_array2d.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_array2d.m,v
retrieving revision 1.6
diff -u -r1.6 version_array2d.m
--- library/version_array2d.m	27 Sep 2006 06:16:44 -0000	1.6
+++ library/version_array2d.m	5 May 2011 04:10:56 -0000
@@ -37,18 +37,22 @@
      % An exception is thrown if the sublists are not all the same length.
      %
  :- func version_array2d(list(list(T))) = version_array2d(T).
+ 
+    % init(M, N, X) = version_array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]])
+    % where each XIJ = X.
+    %
+    % An exception is thrown if M < 0 or N < 0.
+    %
+:- func init(int, int, T) = version_array2d(T).

      % new(M, N, X) = version_array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]])
      % where each XIJ = X.
      %
      % An exception is thrown if M < 0 or N < 0.
      %
+:- pragma obsolete(new/3).
  :- func new(int, int, T) = version_array2d(T).

-    % A synonym for new/3.
-    %
-:- func init(int, int, T) = version_array2d(T).
-
      % version_array2d([[X11, ..., X1N], ..., [XM1, ..., XMN]]) ^ elem(I, J) = X
      % where X is the J+1th element of the I+1th row (i.e. indices start from
      % zero.)
@@ -135,13 +139,13 @@

  %-----------------------------------------------------------------------------%

-new(M, N, X) =
+init(M, N, X) =
      ( if    M >= 0, N >= 0
-      then  version_array2d(M, N, version_array.new(M * N, X))
+      then  version_array2d(M, N, version_array.init(M * N, X))
        else  func_error("version_array2d.new: bounds must be non-negative")
      ).

-init(M, N, X) = new(M, N, X).
+new(M, N, X) = init(M, N, X).

  %-----------------------------------------------------------------------------%

@@ -188,7 +192,7 @@
  %-----------------------------------------------------------------------------%

  resize(VA2D0, M, N, X) = VA2D :-
-    VA2D1 = new(M, N, X),
+    VA2D1 = init(M, N, X),
      bounds(VA2D0, M0, N0),
      M1    = min(M0, M),
      N1    = min(N0, N),
Index: library/version_bitmap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_bitmap.m,v
retrieving revision 1.9
diff -u -r1.9 version_bitmap.m
--- library/version_bitmap.m	30 Dec 2010 11:18:04 -0000	1.9
+++ library/version_bitmap.m	8 May 2011 13:45:02 -0000
@@ -29,11 +29,18 @@
  %-----------------------------------------------------------------------------%

  :- type version_bitmap.
+ 
+    % init(N, B) creates a version_bitmap of size N (indexed 0 .. N-1)
+    % setting each bit if B = yes and clearing each bit if B = no.
+    % An exception is thrown if N is negative.
+    %
+:- func init(int, bool) = version_bitmap.

      % new(N, B) creates a version_bitmap of size N (indexed 0 .. N-1)
      % setting each bit if B = yes and clearing each bit if B = no.
      % An exception is thrown if N is negative.
      %
+:- pragma obsolete(new/2).
  :- func new(int, bool) = version_bitmap.

      % Returns the number of bits in a version_bitmap.
@@ -130,9 +137,11 @@

  %-----------------------------------------------------------------------------%

-new(N, B) = BM :-
+new(N, B) = init(N, B).
+
+init(N, B) = BM :-
      ( if N < 0 then
-        throw(software_error("version_bitmap.new: negative size"))
+        throw(software_error("version_bitmap.init: negative size"))
        else
          X    = initializer(B),
          BM0  = (version_array.init(num_ints_required(N), X) ^ elem(0) := N),
@@ -143,11 +152,11 @@

  resize(BM0, N, B) = BM :-
      ( if N =< 0 then
-        BM      = new(N, B)
+        BM = init(N, B)
        else
-        X       = initializer(B),
+        X = initializer(B),
          NumInts = num_ints_required(N),
-        BM1     = version_array.resize(BM0, NumInts, X),
+        BM1 = version_array.resize(BM0, NumInts, X),

              % Now we need to ensure that bits N, N+1, N+2, ... up to
              % the word boundary are initialized properly.
Index: library/version_hash_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_hash_table.m,v
retrieving revision 1.16
diff -u -r1.16 version_hash_table.m
--- library/version_hash_table.m	23 Sep 2010 05:31:59 -0000	1.16
+++ library/version_hash_table.m	8 May 2011 14:06:38 -0000
@@ -1,8 +1,9 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 2004-2006, 2010 The University of Melbourne.
  % This file may only be copied under the terms of the GNU Library General
  % Public License - see the file COPYING.LIB in the Mercury distribution.
-% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
  %-----------------------------------------------------------------------------%
  %
  % File: version_hash_table.m.
@@ -34,7 +35,7 @@
  :- type hash_pred(K) == ( pred(K,  int)        ).
  :- inst hash_pred    == ( pred(in, out) is det ).

-    % new(HashPred, N, MaxOccupancy)
+    % init(HashPred, N, MaxOccupancy)
      % constructs a new hash table with initial size 2 ^ N that is
      % doubled whenever MaxOccupancy is achieved; elements are
      % indexed using HashPred.
@@ -46,12 +47,16 @@
      % XXX Values too close to the limits may cause bad things
      % to happen.
      %
+:- func init(hash_pred(K)::in(hash_pred), int::in, float::in) = 
+    (version_hash_table(K, V)::out) is det.
+
+:- pragma obsolete(new/3).
  :- func new(hash_pred(K)::in(hash_pred), int::in, float::in) =
-            (version_hash_table(K, V)::out) is det.
+    (version_hash_table(K, V)::out) is det.

-    % unsafe_new(HashPred, N, MaxOccupancy)
+    % unsafe_init(HashPred, N, MaxOccupancy)
      %
-    % Like new/3, but the constructed hash table is backed by a non-thread safe
+    % Like init/3, but the constructed hash table is backed by a non-thread safe
      % version array. It is unsafe to concurrently access or update the hash
      % table from different threads, or any two hash tables which were produced
      % from operations on the same original hash table.
@@ -59,22 +64,34 @@
      % manner, a non-thread safe hash table can be much faster than a thread
      % safe one.
      %
+:- func unsafe_init(hash_pred(K)::in(hash_pred), int::in, float::in) =
+   (version_hash_table(K, V)::out) is det.
+
+:- pragma obsolete(unsafe_new/3).
  :- func unsafe_new(hash_pred(K)::in(hash_pred), int::in, float::in) =
-            (version_hash_table(K, V)::out) is det.
+   (version_hash_table(K, V)::out) is det.

-    % new_default(HashFn) constructs a hash table with default size and
+    % init_default(HashFn) constructs a hash table with default size and
      % occupancy arguments.
      %
+:- func init_default(hash_pred(K)::in(hash_pred)) =
+   (version_hash_table(K, V)::out) is det.
+
+:- pragma obsolete(new_default/1).
  :- func new_default(hash_pred(K)::in(hash_pred)) =
-            (version_hash_table(K, V)::out) is det.
+   (version_hash_table(K, V)::out) is det.

-    % unsafe_new_default(HashFn)
+    % unsafe_init_default(HashFn)
      %
-    % Like new_default/3 but the constructed hash table is backed by a
-    % non-thread safe version array. See the description of unsafe_new/3 above.
+    % Like init_default/3 but the constructed hash table is backed by a
+    % non-thread safe version array. See the description of unsafe_init/3 above.
      %
+:- func unsafe_init_default(hash_pred(K)::in(hash_pred)) =
+   (version_hash_table(K, V)::out) is det.
+
+:- pragma obsolete(unsafe_new_default/1).
  :- func unsafe_new_default(hash_pred(K)::in(hash_pred)) =
-            (version_hash_table(K, V)::out) is det.
+   (version_hash_table(K, V)::out) is det.

      % Retrieve the hash_pred associated with a hash table.
      %
@@ -211,14 +228,18 @@

  %-----------------------------------------------------------------------------%

-new(HashPred, N, MaxOccupancy) = new_2(HashPred, N, MaxOccupancy, yes).
+init(HashPred, N, MaxOccupancy) = init_2(HashPred, N, MaxOccupancy, yes).

-unsafe_new(HashPred, N, MaxOccupancy) = new_2(HashPred, N, MaxOccupancy, no).
+new(HashPred, N, MaxOccupancy) = init_2(HashPred, N, MaxOccupancy, yes).

-:- func new_2(hash_pred(K)::in(hash_pred), int::in, float::in, bool::in) =
-            (version_hash_table(K, V)::out) is det.
+unsafe_init(HashPred, N, MaxOccupancy) = init_2(HashPred, N, MaxOccupancy, no).

-new_2(HashPred, N, MaxOccupancy, NeedSafety) = HT :-
+unsafe_new(HashPred, N, MaxOccupancy) = init_2(HashPred, N, MaxOccupancy, no).
+
+:- func init_2(hash_pred(K)::in(hash_pred), int::in, float::in, bool::in) =
+    (version_hash_table(K, V)::out) is det.
+
+init_2(HashPred, N, MaxOccupancy, NeedSafety) = HT :-
      (      if N =< 0 then
              throw(software_error("version_hash_table.new_hash_table: N =< 0"))
        else if N >= int.bits_per_int then
@@ -232,7 +253,7 @@
              MaxOccupants = ceiling_to_int(float(NumBuckets) * MaxOccupancy),
              (
                  NeedSafety = yes,
-                Buckets = version_array.new(NumBuckets, ht_nil)
+                Buckets = version_array.init(NumBuckets, ht_nil)
              ;
                  NeedSafety = no,
                  Buckets = version_array.unsafe_new(NumBuckets, ht_nil)
@@ -244,9 +265,11 @@

      % These numbers are picked out of thin air.
      %
-new_default(HashPred) = new(HashPred, 7, 0.9).
+init_default(HashPred) = init(HashPred, 7, 0.9).
+new_default(HashPred) = init(HashPred, 7, 0.9).

-unsafe_new_default(HashPred) = unsafe_new(HashPred, 7, 0.9).
+unsafe_init_default(HashPred) = unsafe_init(HashPred, 7, 0.9).
+unsafe_new_default(HashPred) = unsafe_init(HashPred, 7, 0.9).

  %-----------------------------------------------------------------------------%

@@ -421,18 +444,16 @@
      = assoc_list(K, V).

  to_assoc_list_2(ht_nil, AList) = AList.
-
  to_assoc_list_2(ht_cons(K, V, T), AList) =
      to_assoc_list_2(T, [K - V | AList]).


-from_assoc_list(HP, AList) = from_assoc_list_2(AList, new_default(HP)).
+from_assoc_list(HP, AList) = from_assoc_list_2(AList, init_default(HP)).

  :- func from_assoc_list_2(assoc_list(K, V), version_hash_table(K, V))
      = version_hash_table(K, V).

  from_assoc_list_2([], HT) = HT.
-
  from_assoc_list_2([K - V | AList], HT) =
      from_assoc_list_2(AList, HT ^ elem(K) := V).

@@ -674,4 +695,5 @@
      dynamic_cast(X, A `with_type` array(ArgType)).

  %-----------------------------------------------------------------------------%
+:- end_module version_hash_table.
  %-----------------------------------------------------------------------------%
Index: library/version_store.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/version_store.m,v
retrieving revision 1.6
diff -u -r1.6 version_store.m
--- library/version_store.m	27 Sep 2006 06:16:45 -0000	1.6
+++ library/version_store.m	8 May 2011 13:47:19 -0000
@@ -36,6 +36,11 @@
      % the compiler can automatically detect any attempt to use a
      % mutvar with the wrong version store.
      %
+:- some [S] func init = version_store(S).
+
+    % A synonym for the above.
+    %
+:- pragma obsolete(new/0).
  :- some [S] func new = version_store(S).

      % new_mutvar(X, Mutvar, VS0, VS) adds a new mutvar with value reference X
@@ -117,13 +122,15 @@

  %-----------------------------------------------------------------------------%

-new = version_store(VA) `with_type` version_store(some_version_store_type) :-
+init = version_store(VA) `with_type` version_store(some_version_store_type) :-

          % 256 is just a magic number.  The version_store is resized by
          % doubling if necessary when adding a new mutvar.  Index 0 of
          % the version_store holds a counter for allocating new mutvars.
          %
-    VA = version_array.new(256, univ(counter.init(1) `with_type` counter)).
+    VA = version_array.init(256, univ(counter.init(1) `with_type` counter)).
+
+new = init.

  %-----------------------------------------------------------------------------%

Index: ssdb/ssdb.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/ssdb/ssdb.m,v
retrieving revision 1.37
diff -u -r1.37 ssdb.m
--- ssdb/ssdb.m	3 May 2011 04:35:02 -0000	1.37
+++ ssdb/ssdb.m	5 May 2011 04:36:31 -0000
@@ -2776,7 +2776,7 @@

  :- func new_breakpoints_filter = (bitmap::bitmap_uo) is det.

-new_breakpoints_filter = bitmap.new(breakpoints_filter_mask + 1).
+new_breakpoints_filter = bitmap.init(breakpoints_filter_mask + 1).

  :- func breakpoints_filter_mask = int.


--------------------------------------------------------------------------
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