caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Random results
@ 2001-04-21  3:25 markus.kliegl
  2001-04-21  4:31 ` Patrick M Doane
  0 siblings, 1 reply; 3+ messages in thread
From: markus.kliegl @ 2001-04-21  3:25 UTC (permalink / raw)
  To: Caml List

Hi,

Sorry for the length of the message.

I have the following program:
let rot = ref false;;

let rot13_char c =
  let x = int_of_char c in
    if (x >= 65 && x < 78) || (x >= 97 && x < 110) then
      char_of_int (x + 13)
    else if (x >= 78 && x < 91) || (x >= 110 && x < 123) then
      char_of_int (x - 13)
    else c
;;

let rot13_str str =
  for i = 0 to String.length str - 1 do
    str.[i] <- (rot13_char str.[i])
  done;
  str
;;

let rot_print str =
  if !rot = false then
    print_endline str
  else
    print_endline (rot13_str str)
;;

let rec beer n =
  if n = 1 then begin
    rot_print "1 bottle of beer on the wall";
    rot_print "1 bottle of beer";
    rot_print "Take one down and pass it around";
    rot_print "No bottles of beer on the wall"
  end else begin
    print_int n; rot_print " bottles of beer on the wall";
    print_int n; rot_print " bottles of beer";
    rot_print "Take one down and pass it around";
    print_int (n - 1); rot_print " bottles of beer on the wall";
    print_newline ();
    beer (n - 1)
  end
;;

let main argc argv =
  if (argc > 1) && (argv.(1) = "rot13") then
    rot := true;
  beer 99
;;

main (Array.length Sys.argv) Sys.argv

When running it without the optional argument 'rot13', the
output is correct. However, when I do run it with that argument,
I get results in which some lines are rot13-ed and others not,
e.g.:
3 obggyrf bs orre ba gur jnyy
3 obggyrf bs orre
Gnxr bar qbja naq cnff vg nebhaq
2 obggyrf bs orre ba gur jnyy

2 bottles of beer on the wall
2 bottles of beer
Take one down and pass it around
1 bottles of beer on the wall

1 obggyr bs orre ba gur jnyy
1 obggyr bs orre
Gnxr bar qbja naq cnff vg nebhaq
Ab obggyrf bs orre ba gur jnyy

I'm using Ocaml 3.00, by the way. Is this a bug in my program
(I can't find it) or in Ocaml?

Thanks,
Markus Kliegl

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-04-21  4:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20010420211305.A7171@opus.davidb.org>
2001-04-21  4:33 ` [Caml-list] Random results markus.kliegl
2001-04-21  3:25 markus.kliegl
2001-04-21  4:31 ` Patrick M Doane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).