for review: add a new pred to array.m

Thomas Charles Conway conway at hydra.cs.mu.oz.au
Tue Mar 30 16:07:05 AEST 1999


Hi

For anyone to review.
As suggested by the comments, there may be a (tricky) more efficient
implementation (same O(), better constant factors/better memory usage).
If anyone wants to improve the implementation, I'm quite open to
suggestions.

Thomas
-- 
Thomas Conway <conway at cs.mu.oz.au> )O+
To a killer whale, otters are like hairy popcorn -- Paul Dayton


Add a new predicate to array.m: array__map.

NEWS:
	mention the new predicate.

library/array.m:
	add the new predicate array__map/3.

cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/staff/zs/imp/mercury/NEWS,v
retrieving revision 1.140
diff -u -r1.140 NEWS
--- NEWS	1999/03/24 05:32:17	1.140
+++ NEWS	1999/03/30 05:38:06
@@ -39,6 +39,10 @@
 Changes to the Mercury standard library:
 ****************************************
 
+* We've added a new higher order predicate the array module in the
+  standard library:
+	array__map/3.
+
 * We've added a new predicate to the Mercury standard library:
 	bag__count_value/3.
 
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/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
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/dynamic_linking
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
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/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
Index: library/array.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/array.m,v
retrieving revision 1.52
diff -u -r1.52 array.m
--- array.m	1999/03/22 08:08:40	1.52
+++ array.m	1999/03/30 05:36:31
@@ -209,6 +209,11 @@
 :- mode array__bsearch(array_ui, in, pred(in, in, out) is det, out) is det.
 :- mode array__bsearch(in, in, pred(in, in, out) is det, out) is det.
 
+	% array__map(Closure, OldArray, NewArray) applys `Closure' to
+	% each of the elements of `OldArray' to create `NewArray'.
+:- pred array__map(pred(T, U), array(T), array(U)).
+:- mode array__map(pred(in, out) is det, array_di, array_uo) is det.
+
 %-----------------------------------------------------------------------------%
 :- implementation.
 
@@ -720,6 +725,19 @@
 	        )
 	    )
 	).
+
+%-----------------------------------------------------------------------------%
+
+	% The current implementation of array__map converts to a list,
+	% invokes list__map, then converts back to an array representation.
+	% It would be nicer to be able to do the map on each element
+	% maintaining the same array skeleton. Unfortunately this is
+	% tricky since the intermediate arrays have some elements of
+	% one type, and some of the other.
+array__map(Closure, Array0, Array) :-
+	array__to_list(Array0, List0),
+	list__map(Closure, List0, List),
+	array__from_list(List, Array).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing readline
cvs diff: Diffing readline/doc
cvs diff: Diffing readline/examples
cvs diff: Diffing readline/shlib
cvs diff: Diffing readline/support
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 scripts
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list