From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA10831; Wed, 10 Oct 2001 12:12:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA10535 for ; Wed, 10 Oct 2001 12:12:12 +0200 (MET DST) Received: from maties1.sun.ac.za (maties1.sun.ac.za [146.232.128.1]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f9AAC9122054 for ; Wed, 10 Oct 2001 12:12:10 +0200 (MET DST) Received: from bywoner.sun.ac.za ([146.232.129.121]) by maties1.sun.ac.za with esmtp (Exim 3.33 #3) id 15rGLL-00014E-00 for caml-list@inria.fr; Wed, 10 Oct 2001 12:12:03 +0200 Received: from js by bywoner.sun.ac.za with local (Exim 3.22 #1 (Debian)) id 15rGLL-0005MS-00 for ; Wed, 10 Oct 2001 12:12:03 +0200 To: ocaml mailing list Subject: [Caml-list] out-of-bound array or string access From: Johann Spies Date: 10 Oct 2001 12:12:03 +0200 Message-ID: <874rp7reh8.fsf@bywoner.sun.ac.za> User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scanner: exiscan *15rGLL-00014E-00*DS3kewIH/Tw* http://duncanthrax.net/exiscan/ Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk When I run this small program I get the following results: ------------------------ $ ./paaiement 10000 13.5 5 Die paaiement is R230.10 -------------------------- All arguments correct. Result as expected... -------------------------- $ ./paaiement 10000 -13.5 5 Die rentekoers (-13.500000) moet tussen 0 en 100.0 wees ------------------------- Second argument negative - not acceptable. Output as expected. ------------------------------- $ ./paaiement 10000 -13.5 5 6 Gebruik: paaiement -------------------------------- Arguments > 4 - output as expected. ------------------------------- $ ./paaiement 10000 -13.5 Fatal error: uncaught exception Invalid_argument("out-of-bound array or string access") --------------------------------- Arguments < 4 - unexpected error. Why did "if Array.length Sys.argv <> 4 then " not catch this? The code: ------------------------------------------- let maandelikse_koers koers = koers /. 100.0/. 12.0;; let n jare = jare *. 12.0;; let paaiement rentekoers jare bedrag = (bedrag *. (maandelikse_koers rentekoers) /. (1.0 -. exp ((-.n jare) *. log (1.0 +. (maandelikse_koers rentekoers)))));; let bedrag = float_of_string Sys.argv.(1);; let rentekoers = float_of_string Sys.argv.(2);; let jare = float_of_string Sys.argv.(3);; let main() = if Array.length Sys.argv <> 4 then begin print_string "Gebruik: paaiement \n"; print_newline(); exit 2 end else if rentekoers >= 0. then Printf.printf "\nDie paaiement is R%04.2f\n" (paaiement rentekoers jare bedrag) else begin Printf.printf "Die rentekoers (%f) moet tussen 0 en 100.0 wees" rentekoers ; print_newline(); exit 2; end ;; main(); print_newline(); ------------------------------------------------- I am again missing something here. Regards Johann -- Johann Spies Telefoon: 021-808 4036 Informasietegnologie, Universiteit van Stellenbosch "He that covereth his sins shall not prosper; but whoso confesseth and forsaketh them shall have mercy." Proverbs 28:13 ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr