[m-rev.] diff: add svlist to stdlib

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jun 2 17:18:03 AEST 2011


Branches: main

Add a new library module, svlist, that provides state variable friendly
versions of some predicates in the list module.

library/svlist.m:
 	Add the new module.

library/library.m:
 	Include the new module in the library.

NEWS:
 	Announce the above addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.581
diff -u -r1.581 NEWS
--- NEWS	29 May 2011 17:21:15 -0000	1.581
+++ NEWS	2 Jun 2011 06:52:06 -0000
@@ -146,11 +146,11 @@
    except that it throws an exception instead of failing if the priority queue
    is empty.

-* The new modules svstack and svpqueue provide state variable friendly
-  versions of predicates in the stack and pqueue modules.
+* The new modules svlist, svstack and svpqueue provide state variable friendly
+  versions of predicates in the list, stack and pqueue modules.
    (As with the other sv* modules these modules are intended to pave the
    way for an eventual change of the predicate argument ordering in the
-  stack and pqueue modules.)
+  list, stack and pqueue modules.)

  * We have added additional modes with unique and mostly-unique accumulators
    to rbtree.foldl/4, rbtree.foldl2/6 and tree_bitset.foldl/4.
Index: library/library.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.131
diff -u -r1.131 library.m
--- library/library.m	18 May 2011 11:23:05 -0000	1.131
+++ library/library.m	2 Jun 2011 06:23:34 -0000
@@ -118,6 +118,7 @@
  :- import_module svbag.
  :- import_module svbimap.
  :- import_module sveqvclass.
+:- import_module svlist.
  :- import_module svmap.
  :- import_module svmulti_map.
  :- import_module svpqueue.
@@ -296,6 +297,7 @@
  mercury_std_library_module("svbag").
  mercury_std_library_module("svbimap").
  mercury_std_library_module("sveqvclass").
+mercury_std_library_module("svlist").
  mercury_std_library_module("svmap").
  mercury_std_library_module("svmulti_map").
  mercury_std_library_module("svpqueue").
Index: library/svlist.m
===================================================================
RCS file: library/svlist.m
diff -N library/svlist.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/svlist.m	2 Jun 2011 06:57:25 -0000
@@ -0,0 +1,104 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+% Copyright (C) 2011 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.
+%---------------------------------------------------------------------------%
+%
+% File: svpqueue.m.
+% Main author: conway.
+% Stability: high.
+%
+% This file provides an interface to the 'list' ADT that is conducive to the
+% use of state variable notation. The predicates here do the same thing as
+% their counterparts in the pqueue module; the only difference is the order
+% of the arguments.
+%
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- module svlist.
+:- interface.
+
+:- import_module list.
+
+%---------------------------------------------------------------------------%
+
+    % svlist.delete(Elem, List, Remainder):
+    %
+    % True iff `Elem' occurs in `List', and `Remainder' is the result of
+    % deleting one occurrence of `Elem' from `List'.
+    %
+:- pred svlist.delete(T, list(T), list(T)).
+:- mode svlist.delete(in, in, in) is semidet.
+:- mode svlist.delete(in, in, out) is nondet.
+:- mode svlist.delete(out, in, out) is nondet.
+:- mode svlist.delete(in, out, in) is multi.
+
+    % svlist.delete_first(Elem, List0, List) is true iff Elem occurs in List0
+    % and List is List0 with the first occurrence of Elem removed.
+    %
+:- pred svlist.delete_first(T::in, list(T)::in, list(T)::out) is semidet.
+
+    % svlist.delete_elems(Elems, List0, List) is true iff List is List0 with
+    % all occurrences of all elements of Elems removed.
+    %
+:- pred svlist.delete_elems(list(T)::in, list(T)::in, list(T)::out) is det.
+ 
+    % svlist.replace(D, R, List0, List) is true iff List is List0
+    % with an occurrence of D replaced with R.
+    %
+:- pred svlist.replace(T, T, list(T), list(T)).
+:- mode svlist.replace(in, in, in, in) is semidet.
+:- mode svlist.replace(in, in, in, out) is nondet.
+ 
+    % svlist.replace_first(D, R, List0, List) is true iff List is List0
+    % with the first occurrence of D replaced with R.
+    %
+:- pred svlist.replace_first(T::in, T::in, list(T)::in, list(T)::out)
+    is semidet.
+
+    % svlist.replace_all(D, R, List0, List) is true iff List is List0
+    % with all occurrences of D replaced with R.
+    %
+:- pred svlist.replace_all(T::in, T::in, list(T)::in, list(T)::out) is det.
+ 
+    % svlist.det_replace_nth(N, R, List0, List) is true iff List is List0
+    % with Nth element replaced with R.
+    % Aborts if N < 1 or if length of List0 < N.
+    % (Position numbers start from 1.)
+    %
+:- pred svlist.det_replace_nth(int::in, T::in, list(T)::in, list(T)::out)
+    is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+svlist.delete(E, !List) :-
+    list.delete(!.List, E, !:List).
+
+svlist.delete_first(E, !List) :-
+    list.delete_first(!.List, E, !:List).
+
+svlist.delete_elems(Elems, !List) :-
+    list.delete_elems(!.List, Elems, !:List).
+
+svlist.replace(D, R, !List) :-
+    list.replace(!.List, D, R, !:List).
+
+svlist.replace_first(D, R, !List) :-
+    list.replace_first(!.List, D, R, !:List).
+
+svlist.replace_all(D, R, !List) :-
+    list.replace_all(!.List, D, R, !:List).
+
+svlist.det_replace_nth(N, R, !List) :-
+    list.det_replace_nth(!.List, N, R, !:List).
+
+%---------------------------------------------------------------------------%
+:- end_module svlist.
+%---------------------------------------------------------------------------%

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