[m-rev.] diff: clean up deconstruct and std_util

Peter Ross pro at missioncriticalit.com
Tue Dec 3 23:31:28 AEDT 2002


Hi,


===================================================================


Estimated hours taken: 1
Branches: main

Fix some incorrect behaviour when attempting to use the
include_details_cc mode of various predicates.

library/deconstruct.m:
    Constrain arg and limited_construct so that they are only called for
    the do_not_allow and canonicalize cases, so that users get an error
    message when attempting to use the include_details_cc mode.
    Rewrite det_arg so that it work for the include_details_cc case.

library/std_util.m:
    Rewrite argument_cc to use arg_cc.

Index: library/deconstruct.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/deconstruct.m,v
retrieving revision 1.19
diff -u -r1.19 deconstruct.m
--- library/deconstruct.m	3 Dec 2002 10:09:19 -0000	1.19
+++ library/deconstruct.m	3 Dec 2002 10:40:44 -0000
@@ -122,8 +122,6 @@
 :- some [ArgT] pred arg(T, noncanon_handling, int, ArgT).
 :- mode arg(in, in(do_not_allow), in, out) is semidet.
 :- mode arg(in, in(canonicalize), in, out) is semidet.
-:- mode arg(in, in(include_details_cc), in, out) is erroneous.
-:- mode arg(in, in, in, out) is semidet.
 
 	% See the documentation of std_util__arg_cc
 :- pred arg_cc(T, int, std_util__maybe_arg).
@@ -150,7 +148,7 @@
 :- mode det_arg(in, in(do_not_allow), in, out) is det.
 :- mode det_arg(in, in(canonicalize), in, out) is det.
 :- mode det_arg(in, in(include_details_cc), in, out) is cc_multi.
-:- mode det_arg(in, in, in, out) is det.
+:- mode det_arg(in, in, in, out) is cc_multi.
 
 	% det_named_arg(Data, NonCanon, Name, Argument)
 	%
@@ -201,9 +199,6 @@
 	is semidet.
 :- mode limited_deconstruct(in, in(canonicalize), in, out, out, out)
 	is semidet.
-:- mode limited_deconstruct(in, in(include_details_cc), in, out, out, out)
-	is erroneous.
-:- mode limited_deconstruct(in, in, in, out, out, out) is semidet.
 
 	% See the documentation of std_util__limited_deconstruct_cc.
 :- pred limited_deconstruct_cc(T, int, maybe({string, int, list(univ)})).
@@ -314,20 +309,24 @@
 	Argument = univ_value(Univ).
 
 det_arg(Term, NonCanon, Index, Argument) :-
-	(
-		(
-			NonCanon = do_not_allow,
-			univ_arg_dna(Term, Index, Univ)
+	( NonCanon = do_not_allow,
+		( univ_arg_dna(Term, Index, Univ) ->
+			MaybeArg = yes(Univ)
 		;
-			NonCanon = canonicalize,
-			univ_arg_can(Term, Index, Univ)
+			MaybeArg = no
+		)
+	; NonCanon = canonicalize,
+		( univ_arg_can(Term, Index, Univ) ->
+			MaybeArg = yes(Univ)
 		;
-			NonCanon = include_details_cc,
-			error("deconstruct__arg called with include_details_cc")
+			MaybeArg = no
 		)
-	->
-		Argument = univ_value(Univ)
-	;
+	; NonCanon = include_details_cc,
+		univ_arg_idcc(Term, Index, MaybeArg)
+	),
+	( MaybeArg = yes(UnivArg),
+		Argument = univ_value(UnivArg)
+	; MaybeArg = no,
 		error("det_arg: argument number out of range")
 	).
 
Index: library/std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.276
diff -u -r1.276 std_util.m
--- library/std_util.m	3 Dec 2002 10:09:19 -0000	1.276
+++ library/std_util.m	3 Dec 2002 10:27:28 -0000
@@ -631,14 +631,14 @@
 	% equality predicate.)
 	%
 	% arg_cc and argument_cc succeed even if the first argument is
-	% of a non-canonical type.  arg_cc encodes the possible
+	% of a non-canonical type.  They both encode the possible
 	% non-existence of an argument at the requested location by using
 	% a maybe type.
 	%
 :- func arg(T::in, int::in) = (ArgT::out) is semidet.
 :- pred arg_cc(T::in, int::in, maybe_arg::out) is cc_multi.
 :- func argument(T::in, int::in) = (univ::out) is semidet.
-:- pred argument_cc(T::in, int::in, univ::out) is cc_nondet.
+:- pred argument_cc(T::in, int::in, maybe(univ)::out) is cc_multi.
 
 	% named_argument(Data, ArgumentName) = ArgumentUniv
 	%
@@ -1629,9 +1629,14 @@
 	deconstruct__arg(Term, canonicalize, Index, Argument),
 	type_to_univ(Argument, ArgumentUniv).
 
-argument_cc(Term, Index, ArgumentUniv) :-
-	deconstruct__arg(Term, include_details_cc, Index, Argument),
-	type_to_univ(Argument, ArgumentUniv).
+argument_cc(Term, Index, MaybeArgumentUniv) :-
+	deconstruct__arg_cc(Term, Index, MaybeArgument),
+	( MaybeArgument = arg(Argument),
+		type_to_univ(Argument, ArgumentUniv),
+		MaybeArgumentUniv = yes(ArgumentUniv)
+	; MaybeArgument = no_arg,
+		MaybeArgumentUniv = no
+	).
 
 named_argument(Term, Name) = ArgumentUniv :-
 	deconstruct__named_arg(Term, canonicalize, Name, Argument),
--------------------------------------------------------------------------
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