[m-dev.] For review: yet another rot13

Ralph Becket rbeck at microsoft.com
Tue Jan 30 01:42:48 AEDT 2001


I got bored...



Estimated hours taken: 0.33

Added a new rot13 implementation to the collection in samples/rot13.

samples/rot13/rot13_ralph.m:
	Added.

samples/rot13/Mmakefile:
	Added `rot13_ralph' to the list of build targets.

Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/rot13/Mmakefile,v
retrieving revision 1.1
diff -u -r1.1 Mmakefile
--- Mmakefile   1998/11/19 06:18:20     1.1
+++ Mmakefile   2001/01/29 14:36:29
@@ -8,7 +8,7 @@
 # To build these programs, first install the Mercury compiler,
 # type `mmake depend', and then type `mmake'.

-PROGS= rot13_gustavo rot13_juergen rot13_verbose rot13_concise
+PROGS= rot13_gustavo rot13_juergen rot13_verbose rot13_concise rot13_ralph

 DEPENDS=$(PROGS:%=%.depend)
===================================================================
samples/rot13/rot13_ralph.m

%
----------------------------------------------------------------------------
%
% rot13_ralph.m
% Ralph Becket <rbeck at microsoft.com>
% Tue Jan  9 18:10:44 GMT 2001
% vim: ts=4 sw=4 et tw=0 wm=0 ff=unix ft=mercury
%
% Short and sweet.
%
%
----------------------------------------------------------------------------
%

:- module rot13_ralph.

:- interface.

:- import_module io.



:- pred main(io__state::di, io__state::uo) is det.

%
----------------------------------------------------------------------------
%
%
----------------------------------------------------------------------------
%

:- implementation.

:- import_module int, require.

%
----------------------------------------------------------------------------
%

main -->
    io__read_byte(Result),
    (   { Result = ok(X) },         io__write_byte(rot13(X)), main
    ;   { Result = eof }
    ;   { Result = error(ErrNo)},   { error(io__error_message(ErrNo)) }
    ).

%
----------------------------------------------------------------------------
%

:- func rot13(int) = int.

rot13(X) =
    (      if 0'a =< X, X =< 0'z then Rot13(X, 0'a)
      else if 0'A =< X, X =< 0'Z then Rot13(X, 0'A)
      else X
    )
 :-
    Rot13 = ( func(X, A) = ((13 + X - A) `rem` 26) + A ).

%
----------------------------------------------------------------------------
%
%
----------------------------------------------------------------------------
%

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 
--------------------------------------------------------------------------
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