[m-rev.] for review: svmap

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Dec 14 12:22:18 AEDT 2004


library/svmap.m:
	Add this new module svmap for making it easier to work with maps in
	code that uses state variables. For every predicate in map.m that
	updates maps, svmap.m contains a predicate doing the same thing
	with an argument order conducive to the use of state variables.

library/library.m:
	Mention the new module.

NEWS:
	Mention the new module.

Zoltan.

cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.352
diff -u -r1.352 NEWS
--- NEWS	10 Dec 2004 09:44:22 -0000	1.352
+++ NEWS	13 Dec 2004 12:36:10 -0000
@@ -21,7 +21,8 @@
   version_array2d, version_bitmap, version_hash_table, and version_store,
   implementing non-unique versions of these types supporting O(1) access for
   non-persistent use.  A new module term_to_xml has been added for converting
-  arbitrary terms to XML documents.
+  arbitrary terms to XML documents. A new module svmap now provides a more
+  convenient way to update maps in code that uses state variables.
 * New procedures have been added to many of the existing standard library
   modules.  Most notably, these include procedures for creating
   directories and symbolic links, for checking file types and file
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/library.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.76
diff -u -r1.76 library.m
--- library/library.m	7 Dec 2004 04:55:49 -0000	1.76
+++ library/library.m	13 Dec 2004 12:09:15 -0000
@@ -96,6 +96,7 @@
 :- import_module std_util.
 :- import_module store.
 :- import_module string.
+:- import_module svmap.
 :- import_module term.
 :- import_module term_io.
 :- import_module term_to_xml.
@@ -213,6 +214,7 @@
 mercury_std_library_module("std_util").
 mercury_std_library_module("store").
 mercury_std_library_module("string").
+mercury_std_library_module("svmap").
 mercury_std_library_module("table_builtin").
 mercury_std_library_module("term").
 mercury_std_library_module("term_io").
Index: library/svmap.m
===================================================================
RCS file: library/svmap.m
diff -N library/svmap.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/svmap.m	13 Dec 2004 12:36:55 -0000
@@ -0,0 +1,132 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 2004 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: svmap.m.
+% Author: zs.
+% Stability: high.
+%
+% This file provides an interface to the 'map' ADT that is conducive to the
+% use of state variable notation. The predicates here do the same thing as
+% their counterparts in the map module; the only difference is the order of the
+% arguments.
+%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- module svmap.
+:- interface.
+:- import_module list, assoc_list, map.
+
+%-----------------------------------------------------------------------------%
+
+	% Insert a new key and corresponding value into a map.
+	% Fail if the key already exists.
+:- pred svmap__insert(K::in, V::in, map(K, V)::in, map(K, V)::out) is semidet.
+
+	% Insert a new key and corresponding value into a map.
+	% Abort if the key already exists.
+:- pred svmap__det_insert(K::in, V::in, map(K, V)::in, map(K, V)::out) is det.
+
+	% Apply map__det_insert to key - value pairs from corresponding lists.
+:- pred svmap__det_insert_from_corresponding_lists(list(K)::in, list(V)::in,
+	map(K, V)::in, map(K, V)::out) is det.
+
+	% Apply map__det_insert to key - value pairs from the assoc_lists.
+:- pred svmap__det_insert_from_assoc_list(assoc_list(K, V)::in,
+	map(K, V)::in, map(K, V)::out) is det.
+
+	% Apply map__set to key - value pairs from corresponding lists.
+:- pred svmap__set_from_corresponding_lists(list(K)::in, list(V)::in,
+	map(K, V)::in, map(K, V)::out) is det.
+
+:- pred svmap__set_from_assoc_list(assoc_list(K, V)::in,
+	map(K, V)::in, map(K, V)::out) is det.
+
+	% Update the value corresponding to a given key
+	% Fail if the key doesn't already exist.
+:- pred svmap__update(K::in, V::in, map(K, V)::in, map(K, V)::out) is semidet.
+
+	% Update the value corresponding to a given key
+	% Abort if the key doesn't already exist.
+:- pred svmap__det_update(K::in, V::in, map(K, V)::in, map(K, V)::out) is det.
+
+	% Update value if the key is already present, otherwise
+	% insert new key and value.
+:- pred svmap__set(K, V, map(K, V), map(K, V)).
+:- mode svmap__set(di, di, di, uo) is det.
+:- mode svmap__set(in, in, in, out) is det.
+
+	% Delete a key-value pair from a map.
+	% If the key is not present, leave the map unchanged.
+:- pred svmap__delete(K, map(K, V), map(K, V)).
+:- mode svmap__delete(in, di, uo) is det.
+:- mode svmap__delete(in, in, out) is det.
+
+	% Apply map__delete/3 to a list of keys.
+:- pred svmap__delete_list(list(K), map(K, V), map(K, V)).
+:- mode svmap__delete_list(in, di, uo) is det.
+:- mode svmap__delete_list(in, in, out) is det.
+
+	% Delete a key-value pair from a map and return the value.
+	% Fail if the key is not present.
+:- pred svmap__remove(K::in, V::out, map(K, V)::in, map(K, V)::out) is semidet.
+
+	% Delete a key-value pair from a map and return the value.
+	% Abort if the key is not present.
+:- pred svmap__det_remove(K::in, V::out, map(K, V)::in, map(K, V)::out) is det.
+
+	% Remove the smallest item from the map, fail if
+	% the map is empty.
+:- pred svmap__remove_smallest(K::out, V::out, map(K, V)::in, map(K, V)::out)
+	is semidet.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+svmap__insert(K, V, Map0, Map) :-
+	map__insert(Map0, K, V, Map).
+
+svmap__det_insert(K, V, Map0, Map) :-
+	map__det_insert(Map0, K, V, Map).
+
+svmap__det_insert_from_corresponding_lists(Ks, Vs, Map0, Map) :-
+	map__det_insert_from_corresponding_lists(Map0, Ks, Vs, Map).
+
+svmap__det_insert_from_assoc_list(As, Map0, Map) :-
+	map__det_insert_from_assoc_list(Map0, As, Map).
+
+svmap__set_from_corresponding_lists(Ks, Vs, Map0, Map) :-
+	map__set_from_corresponding_lists(Map0, Ks, Vs, Map).
+
+svmap__set_from_assoc_list(As, Map0, Map) :-
+	map__set_from_assoc_list(Map0, As, Map).
+
+svmap__update(K, V, Map0, Map) :-
+	map__update(Map0, K, V, Map).
+
+svmap__det_update(K, V, Map0, Map) :-
+	map__det_update(Map0, K, V, Map).
+
+svmap__set(K, V, Map0, Map) :-
+	map__set(Map0, K, V, Map).
+
+svmap__delete(Key, Map0, Map) :-
+	map__delete(Map0, Key, Map).
+
+svmap__delete_list(Keys, Map0, Map) :-
+	map__delete_list(Map0, Keys, Map).
+
+svmap__remove(Key, Value, Map0, Map) :-
+	map__remove(Map0, Key, Value, Map).
+
+svmap__det_remove(Key, Value, Map0, Map) :-
+	map__det_remove(Map0, Key, Value, Map).
+
+svmap__remove_smallest(K, V, Map0, Map) :-
+	map__remove_smallest(Map0, K, V, Map).
+
+%-----------------------------------------------------------------------------%
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list