[m-dev.] Re: [mercury-users] abstract types.

Peter Schachte schachte at cs.mu.OZ.AU
Wed Jan 19 00:03:51 AEDT 2000


On Tue, Jan 18, 2000 at 09:18:45AM +1100, Thomas Conway wrote:
> There's a bit of a problem in making bidirectional functions like this -
> apart from anything else, the code for \/ing the bits together doesn't
> work in the backwards mode (ie:
> 	lr1item(ProdNum, Dot, Sym) = Bits :-
> 		encode_sym(Sym, SymNum),
> 		Bits = (ProdNum << 20) \/ (Dot << 12) \/ SymNum.
> )

I've just submitted a new predicate for the int library module:

	% code(Factor, Value, Residue, Coding)
	% holds iff Factor*Value+Residue = Coding, and 0 <= Value < Factor.w
	% This is useful for things like converting between time as 
	% hours, minutes, and seconds, and raw seconds.

:- pred code(int, int, int, int).
:- mode code(in, in, in, out) is det.
:- mode code(in, out, out, in) is det.

This would let you write

	lr1item(ProdNum, Dot, Sym) = Bits :-
		encode_sym(Sym, SymNum),
		code(256, Dot, Prodnum, Bits0),
		code(4096, SymNum, Bits0, Bits).

and have it work in both modes.

BTW, this is implemented as you suggest with pragma C code, but it's
better to have that in one place, rather than repeated everywhere you
want to do this kind of encoding.


-- 
Peter Schachte                     The mind of a bigot is like the pupil of
mailto:schachte at cs.mu.OZ.AU        the eye. The more light you pour upon it,
http://www.cs.mu.oz.au/~schachte/  the more it will contract.
PGP: finger schachte at 128.250.37.3      -- Oliver Wendell Holmes Jr. 
--------------------------------------------------------------------------
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