cvs diff: argument/3, det_argument/3

Tyson Richard DOWD trd at hydra.cs.mu.oz.au
Wed Apr 23 12:21:36 AEST 1997


Hi,

	Fergus, could you review this please?

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

Estimated hours taken: 0.5

library/std_util.m:
	- Add argument/3 and det_argument/3, which act like arg, but
	  have their parameters in the (arguably) more sensible order,
	  and start numbering arguments at 0 rather than 1.

	- arg/3 and det_arg/3 are retained for Prolog compatibility
	  (eventually they will probably go into a compatability
	  library), and are implemented in terms of argument/3 and
	  det_argument/3.

	- Also, comments for functor, arg and expand are cleaned up a
	  little.

Index: std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.78
diff -u -r1.78 std_util.m
--- std_util.m	1997/04/23 02:06:08	1.78
+++ std_util.m	1997/04/23 02:10:10
@@ -130,8 +130,10 @@
 :- func type_of(T) = type_info.
 :- mode type_of(unused) = out is det.
 
-	% num_functors(TypeInfo) returns the number of different functors
-	% for the type specified by TypeInfo, or -1 if the type is not a
+	% num_functors(TypeInfo) 
+	% 
+	% Returns the number of different functors for the type
+	% specified by TypeInfo, or -1 if the type is not a
 	% discriminated union type.
 
 :- func num_functors(type_info) = int.
@@ -163,11 +165,11 @@
 
 %-----------------------------------------------------------------------------%
 
-	% functor, arg and expand take any type (including univ),
+	% functor, argument and expand take any type (including univ),
 	% and return representation information for that type.
 	%
-	% The string representation of the functor that functor and 
-	% expand return is:
+	% The string representation of the functor that `functor' and 
+	% `expand' return is:
 	% 	- for user defined types, the functor that is given
 	% 	  in the type defintion. For lists, this
 	% 	  means the functors ./2 and []/0 are used, even if
@@ -183,19 +185,48 @@
 	%	- for predicates and functions, the string
 	%	  <<predicate>>
 
-	% functor(Data, Functor, Arity), given a data item (Data),
-	% binds Functor to a string representation of the functor
-	% and Arity to the arity of this data item.
+	% functor(Data, Functor, Arity)
+	% 
+	% Given a data item (Data), binds Functor to a string
+	% representation of the functor and Arity to the arity of this
+	% data item.
 
 :- pred functor(T::in, string::out, int::out) is det.
 
-	% arg(ArgumentIndex, Data, Argument), given a data item (Data)
-	% and an argument index (ArgumentIndex), starting at 1 for the
-	% first argument, binds Argument to that argument of the functor
-	% of the data item. If the argument index is out of range -
-	% that is higher than the arity of the functor or lower than 1,
-	% arg/3 fails.
-	% The argument has the type univ. 
+	% argument(Date, ArgumentIndex, Argument)
+	% 
+	% Given a data item (Data) and an argument index
+	% (ArgumentIndex), starting at 0 for the first argument, binds
+	% Argument to that argument of the functor of the data item. If
+	% the argument index is out of range - that is greater than or
+	% equal to the arity of the functor or lower than 0, argument/3
+	% fails.  The argument has the type univ. 
+
+:- pred argument(T::in, int::in, univ::out) is semidet.
+
+	% det_argument(ArgumentIndex, Data, Argument)
+	% 
+	% Given a data item (Data) and an argument index
+	% (ArgumentIndex), starting at 0 for the first argument, binds
+	% Argument to that argument of the functor of the data item. If
+	% the argument index is out of range, that is, greater than or
+	% equal to the arity  of the functor or lower than 0, det_arg/3
+	% aborts. 
+
+:- pred det_argument(T::in, int::in, univ::out) is det.
+
+	% arg(ArgumentIndex, Data, Argument) 
+	% 
+	% Given a data item (Data) and an argument index
+	% (ArgumentIndex), starting at 1 for the first argument, binds
+	% Argument to that argument of the functor of the data item. If
+	% the argument index is out of range - that is higher than the
+	% arity of the functor or lower than 1, arg/3 fails.  The
+	% argument has the type univ. 
+	%
+	% NOTE: `arg' is provided for Prolog compatability - the order
+	% of parameters, and first argument number in `arg' are
+	% different from `argument'.
 
 :- pred arg(int::in, T::in, univ::out) is semidet.
 
@@ -1994,7 +2025,7 @@
 
 }").
 
-:- pragma(c_code, arg(ArgumentIndex::in, Type::in, Argument::out), " 
+:- pragma(c_code, argument(Type::in, ArgumentIndex::in, Argument::out), " 
 {
 	ML_Expand_Info info;
 	Word arg_pseudo_type_info;
@@ -2038,13 +2069,19 @@
 
 }").
 
+arg(ArgumentIndex, Type, Argument) :-
+	argument(Type, ArgumentIndex, Argument).
+
 det_arg(ArgumentIndex, Type, Argument) :-
+	det_argument(Type, ArgumentIndex, Argument).
+
+det_argument(Type, ArgumentIndex, Argument) :-
 	(
-		arg(ArgumentIndex, Type, Argument0)
+		argument(Type, ArgumentIndex, Argument0)
 	->
 		Argument = Argument0
 	;
-		error("det_arg : invalid argument")
+		error("det_argument : argument out of range")
 	).
 
 :- pragma(c_code, expand(Type::in, Functor::out, Arity::out, Arguments::out), " 
-- 
       Tyson Dowd           #
                            #             Sign on refrigerator:
     trd at cs.mu.oz.au        #           Refrigerate after opening. 
http://www.cs.mu.oz.au/~trd #                  - C. J. Owen.



More information about the developers mailing list