[m-rev.] for review: improvements for library/ops.m

Simon Taylor stayl at cs.mu.OZ.AU
Sun Nov 4 06:08:32 AEDT 2001


Estimated hours taken: 0.25

NEWS:
library/ops.m:
	Remove the undocumented `export_*', `import_*' and `use_*'
	module system operators, which aren't likely to be
	implemented any time soon, and which can cause syntax
	errors if anyone accidentally uses them.

	Improve the documentation.

	Move some items which are really just implementation
	details to a less prominent position in the interface.

tests/invalid/bigtest.m:
	Fix uses of the removed operators.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.223
diff -u -u -r1.223 NEWS
--- NEWS	3 Nov 2001 17:34:51 -0000	1.223
+++ NEWS	3 Nov 2001 18:55:57 -0000
@@ -36,6 +36,13 @@
   information, see the "Impurity" chapter of the Mercury Language
   Reference Manual.
 
+* We've removed the undocumented operators `export_adt', `export_cons',
+  `export_module', `export_op', `export_pred', `export_sym', `export_type',
+  `import_adt', `import_cons', `import_op', `import_pred', `import_sym',
+  `import_type' `use_adt', `use_cons', `use_op', `use_pred', `use_sym'
+  and `use_type'. These operators were reserved for module system
+  extensions which are unlikely to be implemented.
+
 Changes to the Mercury standard library:
 * As mentioned above, the constructor for lists has changed from './2'
   to `[|]/2'. This change affects the behaviour of the term manipulation
Index: library/ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/ops.m,v
retrieving revision 1.33
diff -u -u -r1.33 ops.m
--- library/ops.m	24 Oct 2001 10:42:57 -0000	1.33
+++ library/ops.m	3 Nov 2001 19:04:58 -0000
@@ -18,22 +18,29 @@
 :- module ops.
 :- interface.
 
+	% An ops__specifier describes what structure terms
+	% constructed with an operator are allowed to take.
+	% `f' represents the operator and `x' and `y' represent arguments.
+	% `x' represents an argument whose priority must be
+	% strictly lower that that of the operator.
+	% `y' represents an argument whose priority is
+	% lower or equal to that of the operator.
+	% For example, `yfx' indicates a left-associative infix operator,
+	% while `xfy' indicates a right-associative infix operator.
 :- type ops__specifier
 	--->	fx ; fy ; xf ; yf ; xfx ; yfx ; xfy ; fxx ; fxy ; fyx.
 
 :- type ops__assoc
 	--->	x ; y.
 
-:- type ops__class
-	--->	infix(ops__assoc, ops__assoc)
-	;	prefix(ops__assoc)
-	;	binary_prefix(ops__assoc, ops__assoc)
-	;	postfix(ops__assoc).
+	% Operators with a low "priority" bind more tightly than those
+	% with a high "priority". For example, given that `+' has
+	% priority 500 and `*' has priority 400, the term `2 * X + Y'
+	% would parse as `(2 * X) + Y'.
+:- type ops__priority == int.
 
 :- type ops__table.
 
-:- type ops__priority == int.
-
 	% create an ops_table with the standard Mercury operators.
 :- pred ops__init_op_table(ops__table).
 :- mode ops__init_op_table(uo) is det.
@@ -65,12 +72,6 @@
 :- pred ops__lookup_op(ops__table, string).
 :- mode ops__lookup_op(in, in) is semidet.
 
-	% convert an ops__specifer (e.g. `xfy') to an ops__class
-	% (e.g. `infix(x, y)').
-:- pred ops__op_specifier_to_class(ops__specifier, ops__class).
-:- mode ops__op_specifier_to_class(in, out) is det.
-% :- mode ops__op_specifier_to_class(out, in) is semidet.
-
 	% Returns the highest priority number (the lowest is zero).
 	% Note that due to Prolog tradition, the priority numbers
 	% are backwards: higher numbers mean lower priority
@@ -80,10 +81,28 @@
 
 %-----------------------------------------------------------------------------%
 
+:- type ops__class
+	--->	infix(ops__assoc, ops__assoc)
+	;	prefix(ops__assoc)
+	;	binary_prefix(ops__assoc, ops__assoc)
+	;	postfix(ops__assoc).
+
+	% convert an ops__specifer (e.g. `xfy') to an ops__class
+	% (e.g. `infix(x, y)').
+:- pred ops__op_specifier_to_class(ops__specifier, ops__class).
+:- mode ops__op_specifier_to_class(in, out) is det.
+% :- mode ops__op_specifier_to_class(out, in) is semidet.
+
+%-----------------------------------------------------------------------------%
+
 :- implementation.
 
 :- type ops__table ---> ops__table.	% XXX
 
+	% ops__category is used to index the op_table so that
+	% lookups are semidet rather than nondet.
+	% Prefix and binary_prefix operators have ops__category `before'.
+	% Infix and postfix operators have ops__category `after'.
 :- type ops__category ---> before ; after.
 
 ops__op_specifier_to_class(fx, prefix(x)).
@@ -185,23 +204,10 @@
 ops__op_table("div", after, yfx, 400).		% standard ISO Prolog
 ops__op_table("else", after, xfy, 1170).	% Mercury/NU-Prolog extension
 ops__op_table("end_module", before, fx, 1199).	% Mercury extension
-ops__op_table("export_adt", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("export_cons", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("export_module", before, fx, 1199). % Mercury extension (NYI)
-ops__op_table("export_op", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("export_pred", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("export_sym", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("export_type", before, fx, 1199).	% Mercury extension (NYI)
 ops__op_table("func", before, fx, 800).		% Mercury extension
 ops__op_table("if", before, fx, 1160).		% Mercury/NU-Prolog extension
-ops__op_table("import_adt", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("import_cons", before, fx, 1199).	% Mercury extension (NYI)
 ops__op_table("import_module", before, fx, 1199). % Mercury extension
 ops__op_table("include_module", before, fx, 1199). % Mercury extension
-ops__op_table("import_op", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("import_pred", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("import_sym", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("import_type", before, fx, 1199).	% Mercury extension (NYI)
 ops__op_table("impure", before, fy, 800).	% Mercury extension
 ops__op_table("inst", before, fx, 1199).	% Mercury extension
 ops__op_table("instance", before, fx, 1199).	% Mercury extension
@@ -222,13 +228,7 @@
 ops__op_table("then", after, xfx, 1150).	% Mercury/NU-Prolog extension
 ops__op_table("type", before, fx, 1180).	% Mercury extension
 ops__op_table("typeclass", before, fx, 1199).	% Mercury extension
-ops__op_table("use_adt", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_cons", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_module", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_op", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_pred", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_sym", before, fx, 1199).	% Mercury extension (NYI)
-ops__op_table("use_type", before, fx, 1199).	% Mercury extension (NYI)
+ops__op_table("use_module", before, fx, 1199).	% Mercury extension
 ops__op_table("when", after, xfx, 900).		% NU-Prolog extension (*)
 ops__op_table("where", after, xfx, 1175).	% NU-Prolog extension (*)
 ops__op_table("~", before, fy, 900).		% Goedel (*)
Index: tests/invalid/bigtest.m
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/bigtest.m,v
retrieving revision 1.2
diff -u -u -r1.2 bigtest.m
--- tests/invalid/bigtest.m	14 May 1996 14:31:15 -0000	1.2
+++ tests/invalid/bigtest.m	3 Nov 2001 12:15:56 -0000
@@ -1,6 +1,6 @@
-:- export_sym list/1, append/3, member.
-:- export_pred append/3, member.
-:- export_type list/1, bag.
+:- export_sym((list/1, append/3, member)).
+:- export_pred((append/3, member)).
+:- export_type((list/1, bag)).
 
 fact.
 rule :- fact.
--------------------------------------------------------------------------
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