[m-rev.] for review: unification expressions

Simon Taylor stayl at cs.mu.OZ.AU
Wed Nov 21 18:04:23 AEDT 2001


Estimated hours taken: 0.25
Branches: main

Address Fergus's review comments about the change
to add unification expressions to the language.

doc/reference_manual.texi:
	Be more explicit about the evaluation order
	of unification expressions.

	Fix some formatting errors.

library/ops.m:
	Fix a comment -- `@' is not an ISO Prolog operator,
	it is a Mercury extension.

tests/hard_coded/unify_expression.{m,exp}:
	Test the evaluation order of unification expressions.

Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.225
diff -u -u -r1.225 reference_manual.texi
--- doc/reference_manual.texi	20 Nov 2001 13:54:00 -0000	1.225
+++ doc/reference_manual.texi	21 Nov 2001 06:51:00 -0000
@@ -1067,16 +1067,25 @@
 @subsection Unification expressions
 
 A unification expression is an expression of the form
+
 @example
 X @@ Y
 @end example
+
+ at noindent
 where @var{X} and @var{Y} are data-terms.
 
 The semantics of a unification expression is that @var{X} and @var{Y}
 are unified, and the expression is equivalent to the unified value.
 
+ at w{@code{Z = X @@ Y}} is equivalent to the conjunction
+ at w{@code{Z = X, Z = Y}}.
+
 Unification expressions are most useful when writing switches
- at pxref{Determinism checking and inference}.
+(@pxref{Determinism checking and inference}).  The arguments
+of a unification expression are examined when checking for
+switches.  The arguments of an equivalent user-defined function
+would not be.
 
 For example
 
@@ -1088,8 +1097,10 @@
 is equivalent to 
 
 @example
-p(X, X) :-
-        X = f(_, _).
+p(Y, Z) :-
+        Y = X,
+        Y = f(_, _),
+        Z = X.
 @end example
 
 @node Conditional expressions
Index: library/ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/ops.m,v
retrieving revision 1.37
diff -u -u -r1.37 ops.m
--- library/ops.m	12 Nov 2001 11:08:16 -0000	1.37
+++ library/ops.m	21 Nov 2001 04:54:05 -0000
@@ -291,7 +291,7 @@
 ops__op_table(">=", after, xfx, 700).		% standard ISO Prolog
 ops__op_table(">>", after, yfx, 400).		% standard ISO Prolog
 ops__op_table("?-", before, fx, 1200).		% standard ISO Prolog (*)
-ops__op_table("@", after, xfx, 90).		% standard ISO Prolog
+ops__op_table("@", after, xfx, 90).		% Mercury extension
 ops__op_table("@<", after, xfx, 700).		% standard ISO Prolog
 ops__op_table("@=<", after, xfx, 700).		% standard ISO Prolog
 ops__op_table("@>", after, xfx, 700).		% standard ISO Prolog
Index: tests/hard_coded/unify_expression.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/unify_expression.exp,v
retrieving revision 1.1
diff -u -u -r1.1 unify_expression.exp
--- tests/hard_coded/unify_expression.exp	12 Nov 2001 11:08:17 -0000	1.1
+++ tests/hard_coded/unify_expression.exp	21 Nov 2001 06:42:27 -0000
@@ -1 +1,2 @@
 f(1, 2)
+q failed (as expected)
Index: tests/hard_coded/unify_expression.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/unify_expression.m,v
retrieving revision 1.1
diff -u -u -r1.1 unify_expression.m
--- tests/hard_coded/unify_expression.m	12 Nov 2001 11:08:18 -0000	1.1
+++ tests/hard_coded/unify_expression.m	21 Nov 2001 06:09:54 -0000
@@ -8,7 +8,7 @@
 
 :- implementation.
 
-:- import_module require.
+:- import_module require, std_util.
 
 :- type t
 	--->	f(int, int)
@@ -19,11 +19,28 @@
 		io__write(X),
 		io__nl
 	;
-		io__write_string("failed\n")
+		io__write_string("p failed\n")
+	),
+	( { q(1, 2) } ->
+		print("q succeeded"), nl
+	;
+		print("q failed (as expected)"), nl
 	).
 
 :- pred p(t::in, t::out) is semidet.
 
 p(X @ f(_, _), X).
 p(g(X @ f(_, _)), X).
-p(g(g(_)), _) :- error("p").
+
+:- pred q(int::in, int::in) is semidet.
+q(X, X @ f(_, _)).
+
+:- func f(int, int) = int.
+:- mode f(out, out) = in is det.
+f(1, 2) = _ :-
+	( semidet_succeed ->
+		error("f called")
+	;
+		true
+	).
+
--------------------------------------------------------------------------
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