[m-rev.] Additions to list.m

Ralph Becket rafe at cs.mu.OZ.AU
Thu Dec 13 17:53:02 AEDT 2001


Fergus Henderson, Thursday, 13 December 2001:
> On 13-Dec-2001, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > Additions to list.m.
> 
> The new functions should be noted in the NEWS file.

Done:

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.229
diff -u -r1.229 NEWS
--- NEWS	13 Nov 2001 13:58:27 -0000	1.229
+++ NEWS	13 Dec 2001 06:51:59 -0000
@@ -64,6 +64,11 @@
   extensions which are unlikely to be implemented.
 
 Changes to the Mercury standard library:
+* We've added a func version of error/1, called func_error/1, to require.m.
+* We've added two functions to list.m for mapping functions over
+  corresponding members of lists (list__map_corresponding/3 and
+  list__map_corresponding3/4).
+* We've added cc_multi modes to list__foldl/4 and list__foldr/4.
 * As mentioned above, the constructor for lists has changed from './2'
   to `[|]/2'. This change affects the behaviour of the term manipulation
   predicates in the standard library when dealing with values of

> > Index: list.m
> >  :- mode list__foldl(pred(in, in, out) is semidet, in, in, out) is semidet.
> >  :- mode list__foldl(pred(in, in, out) is nondet, in, in, out) is nondet.
> > +:- mode list__foldl(pred(in, di, uo) is cc_multi, in, di, uo) is cc_multi.
> 
> If you're going to add that mode, I think it would make sense to also add
> 
>    :- mode list__foldl(pred(in, in, out) is cc_multi, in, in, out) is cc_multi.
> 
> > +:- mode list__foldr(pred(in, di, uo) is cc_multi, in, di, uo) is cc_multi.
> 
> Likewise.

Done.

> > @@ -659,7 +676,7 @@
> >  
> >  :- implementation.
> >  
> > -:- import_module bintree_set, require, std_util.
> > +:- import_module bintree_set, require, std_util, exception.
> 
> That shouldn't be needed...
> 
> > +list__map_corresponding3(F, As, Bs, Cs) =
> > +	( if      As = [A | As0], Bs = [B | Bs0], Cs = [C | Cs0] then
> > +		[F(A, B, C) | list__map_corresponding3(F, As0, Bs0, Cs0)]
> > +	  else if As = [],        Bs = [],        Cs = []        then
> > +	  	[]
> > +	  else
> > +	  	throw(software_error(
> > +			"list__map_corresponding3: mismatched list arguments"))
> > +	).
> 
> ... because here you should just use error/1 rather than
> throw(software_error(...)).

Okay, I've added a func version of error/1 to require.m (I had to call
it func_error/1 to avoid ambiguity problems elsewhere - error/1 is a
rather common constructor name):

Index: require.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/require.m,v
retrieving revision 1.28
diff -u -r1.28 require.m
--- require.m	31 Aug 1999 12:55:44 -0000	1.28
+++ require.m	13 Dec 2001 06:45:06 -0000
@@ -24,6 +24,13 @@
 %		This will normally cause execution to abort with an error
 %		message.
 
+:- func func_error(string) = _.
+:- mode func_error(in) = unused is erroneous.
+
+%	func_error(Message)
+%		An expression that results in a `software_error(Message)'
+%		exception being thrown.
+
 :- pred	require(pred, string).
 :- mode	require((pred) is semidet, in) is det.
 
@@ -88,6 +95,12 @@
 
 error(Message) :- 
 	throw(software_error(Message)).
+
+% Hopefully func_error/1 won't be called often (!), so no point inlining it.
+:- pragma no_inline(func_error/1). 
+
+func_error(Message) = _ :-
+	error(Message).
 
 :- end_module require.
 
--------------------------------------------------------------------------
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