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 TAA24535; Fri, 20 Jun 2003 19:34:13 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA25879 for ; Fri, 20 Jun 2003 19:34:11 +0200 (MET DST) Received: from abel.swapping.umh.ac.be (nat.umh.ac.be [193.190.193.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5KHYAT06397 for ; Fri, 20 Jun 2003 19:34:10 +0200 (MET DST) Received: from abel.swapping.umh.ac.be ([127.0.0.1] helo=localhost ident=trch) by abel.swapping.umh.ac.be with esmtp (Exim 3.36 #1 (Debian)) id 19TPnf-0005vp-00; Fri, 20 Jun 2003 19:35:47 +0200 Date: Fri, 20 Jun 2003 19:35:37 +0200 (CEST) Message-Id: <20030620.193537.41989199.debian00@tiscali.be> To: "O'Caml Mailing List" Subject: [Caml-list] int/float_of_string From: Christophe TROESTLER Organization: None X-Spook: covert video smuggle constitution satellite imagery Rubin embassy RSA illuminati Yukon Dateline X-Mailer-URL: http://www.mew.org/ X-Operating-System: GNU/Linux (http://www.linux.org/) X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Mailer: Mew version 3.3rc1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; troestler:01 tiscali:99 3.06:01 intentional:01 scanf:01 chris:01 christophe:01 caml:01 primitives:01 int:01 float:02 exception:02 string:03 suppose:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I noticed that there are some disparities in the way string are converted to int/float : Objective Caml version 3.06+36 (2003-06-19) # int_of_string "34\000xx";; - : int = 34 # float_of_string "34\000xx";; Exception: Failure "float_of_string". Is this intentional? I suppose it is not and float_of_string does the right thing. On a related note, it seems that the only way to decode an int/float within a string is to create a new string containing the substring. Moreover one must know the length of the number in advance. Wouldn't it be useful to have primitives like: int_of_string_at : string -> int -> (int, int) float_of_string_at : string -> int -> (int, float) with usage like let (pos_after_the_number, decoded_number) = float_of_string_at s start ? (I know such thing can be done with Scanf but I believe such primitives can simplify and speed up¹ Scanf with no slowdown on int_of_string / float_of_string.) Cheers, ChriS --- ¹ For what simple minded benchs worth, int_of_string can be as much as 1000% faster than Scanf. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners