[m-dev.] diff: samples/calculator.m: use func instead of pred

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Oct 27 00:13:59 AEST 1999


Estimated hours taken: 0.1

samples/calculator.m:
	Improve the coding style: make `evalexpr'
	a function rather than a predicate.

Workspace: /home/mercury0/fjh/mercury
Index: samples/calculator.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/calculator.m,v
retrieving revision 1.5
diff -u -d -r1.5 calculator.m
--- calculator.m	1997/09/10 11:00:14	1.5
+++ calculator.m	1999/09/27 19:33:02
@@ -40,12 +40,12 @@
 		main	% recursively call ourself for the next line(s)
 	).
 
-:- pred evalexpr(expr::in, int::out) is det.
-evalexpr(number(Num), Num).
-evalexpr(plus(X,Y),  Z) :- evalexpr(X,A), evalexpr(Y,B), Z is A + B.
-evalexpr(minus(X,Y), Z) :- evalexpr(X,A), evalexpr(Y,B), Z is A - B.
-evalexpr(times(X,Y), Z) :- evalexpr(X,A), evalexpr(Y,B), Z is A * B.
-evalexpr(div(X,Y),   Z) :- evalexpr(X,A), evalexpr(Y,B), Z is A // B.
+:- func evalexpr(expr) = int.
+evalexpr(number(Num)) = Num.
+evalexpr(plus(X,Y)) = evalexpr(X) + evalexpr(Y).
+evalexpr(minus(X,Y)) = evalexpr(X) - evalexpr(Y).
+evalexpr(times(X,Y)) = evalexpr(X) * evalexpr(Y).
+evalexpr(div(X,Y)) = evalexpr(X) // evalexpr(Y).
 
 % Simple recursive-descent parser.
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list