caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: markus.kliegl@t-online.de (markus.kliegl)
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Random results
Date: Sat, 21 Apr 2001 05:25:34 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.10.10104210456190.26953-100000@linux.magictux.net> (raw)

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


             reply	other threads:[~2001-04-21  3:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-21  3:25 markus.kliegl [this message]
2001-04-21  4:31 ` Patrick M Doane
     [not found] <20010420211305.A7171@opus.davidb.org>
2001-04-21  4:33 ` markus.kliegl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.10.10104210456190.26953-100000@linux.magictux.net \
    --to=markus.kliegl@t-online.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).