[m-rev.] for review: bug fix for try_all/2
Mark Brown
mark at cs.mu.OZ.AU
Wed Dec 8 18:50:46 AEDT 2004
Hi all,
The following is one possible fix for a bug pointed out by Ian.
Cheers,
Mark.
Estimated hours taken: 0.25
Fix a bug in try_all/2 in the library. The documentation says that it puts
the exception at the end of the result list, but the implementation puts
it at the start (and the test case in tests/hard_coded/exceptions checks
that the exception is at the start).
The fix is to change the documentation to match the implementation. The
rationale for this decision is that it is probably more useful to have the
exception at the start of the list where its presence or absence can be
easily checked.
incremental_try_all/4 retains its old meaning, however.
library/exception.m:
Change the documentation for both try_all and incremental_try_all
to reflect this decision.
NEWS:
Mention the change.
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.350
diff -u -r1.350 NEWS
--- NEWS 11 Nov 2004 13:46:41 -0000 1.350
+++ NEWS 8 Dec 2004 07:38:24 -0000
@@ -205,6 +205,10 @@
* exception.m now contains a predicate throw_if_near_stack_limits which
can be used to prevent an application running out of stack space.
+* We've changed the documented meaning of exception.try_all/2 to put the
+ exception, if it exists, at the start of the list instead of the end.
+ This was the existing behaviour of the implementation.
+
* We've added predicates multi_map.to_flat_assoc_list/2 and
multi_map.from_flat_assoc_list/2.
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.95
diff -u -r1.95 exception.m
--- library/exception.m 16 Aug 2004 03:51:05 -0000 1.95
+++ library/exception.m 8 Dec 2004 07:17:11 -0000
@@ -103,17 +103,16 @@
% Try to find all solutions to Goal(R), using backtracking.
% Collect the solutions found in the ResultList, until
% the goal either throws an exception or fails.
- % If it throws an exception, put that exception at the end of
- % the ResultList.
+ % If it throws an exception, put that exception at the start
+ % of the ResultList.
%
% Declaratively:
% try_all(Goal, ResultList) <=>
% (if
- % list__reverse(ResultList,
- % [Last | AllButLast]),
- % Last = exception(_)
+ % ResultList = [First | AllButFirst],
+ % First = exception(_)
% then
- % all [M] (list__member(M, AllButLast) =>
+ % all [M] (list__member(M, AllButFirst) =>
% (M = succeeded(R), Goal(R))),
% else
% all [M] (list__member(M, ResultList) =>
@@ -141,8 +140,9 @@
% try_all(Goal, Results),
% std_util__unsorted_aggregate(Results, AccumulatorPred,
% Acc0, Acc)
- % except that operationally, the execution of try_all
- % and std_util__unsorted_aggregate is interleaved.
+ % except that declaratively, the exception is placed at the end
+ % of the list if it exists, and that operationally, the execution
+ % of try_all and std_util__unsorted_aggregate is interleaved.
:- pred incremental_try_all(pred(T), pred(exception_result(T), A, A), A, A).
:- mode incremental_try_all(pred(out) is nondet,
--------------------------------------------------------------------------
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