[m-rev.] diff: add cord.{to_list,to_rev_list}

Julien Fischer jfischer at opturion.com
Fri Jan 8 15:30:40 AEDT 2016


Add cord.{to_list,to_rev_list} synonyms.

X.to_list/1 being present as the inverse as X.from_list/1 is the usual
convention in the standard library, which for some reason the cord module does
not follow.

library/cord.m:
     Add the above synonyms.

NEWS:
     Announce their addition.

Julien.

diff --git a/NEWS b/NEWS
index 5f58f09..afca9d5 100644
--- a/NEWS
+++ b/NEWS
@@ -275,6 +275,11 @@ Changes to the Mercury standard library:
    Existing code that uses these modes should replace their use with `in'
    or `out' respectively.

+* The following functions have been added to the cord module
+
+   - to_list/1     (synonym for the existing list/1 function)
+   - to_rev_list/1 (synonym for the existing rev_list/1 function)
+
  Changes to the Mercury compiler:

  * We have added a new option --warn-dead-preds. While the existing option
diff --git a/library/cord.m b/library/cord.m
index 6dc6515..a17b96a 100644
--- a/library/cord.m
+++ b/library/cord.m
@@ -59,10 +59,18 @@
      %
  :- func list(cord(T)) = list(T).

+    % A synonym for the list/1.
+    %
+:- func to_list(cord(T)) = list(T).
+
      % rev_list(Cord) = list.reverse(list(Cord).
      %
  :- func rev_list(cord(T)) = list(T).

+    % A synonym for rev_list/1.
+    %
+:- func to_rev_list(cord(T)) = list(T).
+
      % Succeed iff the given cord is empty.
      %
  :- pred is_empty(cord(T)::in) is semidet.
@@ -304,6 +312,9 @@ list_2([N | Ns], L0) = L :-
          L = list_2([B, A | Ns], L0)
      ).

+to_list(C) =
+    list(C).
+
  rev_list(empty_cord) = [].
  rev_list(nonempty_cord(N)) = rev_list_2([N], []).

@@ -336,6 +347,9 @@ list_reverse_2([], L) = L.
  list_reverse_2([X | Xs], L0) =
      list_reverse_2(Xs, [X | L0]).

+to_rev_list(C) =
+    rev_list(C).
+
  %---------------------------------------------------------------------------%

  cons(X, C) = XC :-



More information about the reviews mailing list