[mercury-users] Mercury programmer required ;-)

Peter Schachte pets at cs.mu.OZ.AU
Fri Sep 25 10:29:32 AEST 1998


On Thu, Sep 24, 1998 at 07:50:19PM +1000, Fergus Henderson wrote:
> This is good; I had a look at the rot13 programs in C, Ada, and ML,
> and none of them would have handled character sets such as EBCDIC correctly.
> 
> I was also glad to see that your program reported input errors
> (and the Mercury runtime will report output errors, so they're covered too).
> Few of the programs in other languages seemed to handle errors properly;
> often they were just silently ignored.

I think you guys are making this too difficult, and thereby making the
language seem overly difficult to program in.  I think the goal should
be to make the program as simple and understandable as possible,
rather than making it ironclad.  Take a look a the web page today and
see what the maintainer says about Mercury.

Here's the Prolog version I sent in.

	:- use_module(library(ctypes)).

	runtime_entry(start) :-
		prompt(_, ''),
		rot13.

	rot13 :-
		get0(Ch),
		(   is_endfile(Ch) ->
			true
		;   rot13_char(Ch, Rot),
		    put(Rot),
		    rot13
		).

	rot13_char(Ch, Rot) :-
		(   is_alpha(Ch) ->
			to_upper(Ch, Up),
			Letter is Up - 0'A,
			Rot is Ch + ((Letter + 13) mod 26) - Letter
		;   Rot = Ch
		).

Does Mercury have some way (other than the foreign interface) to get
the ordinal number of an atomic member of a type?  If not, that might
be a good feature to add for applications such as this.

-- 
Peter Schachte                | What we cannot speak about we must pass over
mailto:pets at cs.mu.OZ.AU       | in silence.
http://www.cs.mu.oz.au/~pets/ |     -- Wittgenstein 
PGP: finger pets at 128.250.37.3 | 



More information about the users mailing list