[m-rev.] lex and moose changed

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Aug 3 22:08:56 AEST 2001


On 03-Aug-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Thu, Aug 02, 2001 at 02:54:22AM -0700, Ralph Becket wrote:
> > digit(0) --> ['0'].
> > ...
> > digit(9) --> ['9'].
> 
> How about putting this in the library somewhere:
> 
> 	in_range(Lo, Hi, Val) -->
> 		[Val],
> 		{ Lo =< Val },
> 		{ Val =< Hi }.
> 
> then you can do:
> 
> 	digit(N) --> in_range('0', '9', D), { N = to_int(D) - to_int('0') }.

I'd recommend

	digit(N) --> [Val], { char__digit_to_int(Val, N), N < 10 }.

> > number(N)     --> number(0, N).
> > number(N0, N) --> ( if digit(D) then number(10 * N0 + D, N)
> >                                 else { N = N0 }
> >                   ).
>
> Your definition of number looks pretty reasonable to me.  If you don't
> define it this way, you'll have to write a separate function to translate
> from a string to a number, which will look a lot like this anwyay.

You wouldn't have to write a separate function for that, since the
Mercury standard library already has one.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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