[mercury-users] Mercury programmer required ;-)

Philip Dart philip at cs.mu.OZ.AU
Fri Sep 25 13:17:52 AEST 1998


> Peter Schachte does have a point about the language looking difficult to
> program in.  This version looks far less daunting, but has the drawback that
> people will probably criticise it for its lack of efficiency (I mean,
> *searching* the string for each character?  :-).  Of course, many of the
> reasons it looks difficult are features that make it good for writing
> *large* systems, not toy programs like this one.

Of course if you want (some level of) efficiency, don't mind being ascii
specific, and want to stick to Mercury types, you can copy the non-table
C version, ie.

:- func rot13(char) = char.
rot13(C0) = C :-
        char:to_int(C0, I0),
        Cap = I0 /\ 32,
        I1 = I0 /\ \ Cap,
        I2 = ((0'A =< I1, I1 =< 0'Z) -> (I1 - 0'A + 13) mod 26 + 0'A ; I1),
        ( char__to_int(C1, Cap \/ I2) -> C = C1 ; error("rot13 result") ).

I'm sure I could come up with a better version for the obfuscated Mercury
competetion though.

Philip

-- 
Philip Dart                             E-Mail: philip at cs.mu.OZ.AU
Department of Computer Science          Telephone: +613 9344 9103
The University of Melbourne             Facsimile: +613 9348 1184
Parkville, Vic 3052, Australia          WWW: http://www.cs.mu.oz.au/~philip/





More information about the users mailing list