Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Random results
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: markus.kliegl@t...
Subject: [Caml-list] Random results
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