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 SAA05784; Wed, 21 May 2003 18:46:07 +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 SAA05690 for ; Wed, 21 May 2003 18:46:06 +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 h4LGk6T15268 for ; Wed, 21 May 2003 18:46:06 +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 19IWlB-0001P5-00; Wed, 21 May 2003 18:48:13 +0200 Date: Wed, 21 May 2003 18:48:12 +0200 (CEST) Message-Id: <20030521.184812.24056832.debian00@tiscali.be> To: "O'Caml Mailing List" Subject: [Caml-list] Scanf and objects From: Christophe TROESTLER Organization: None X-Spook: Peking militia number key Waco, Texas Bellcore Craig Livingstone embassy Albanian propaganda Leitrim 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.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; troestler:01 tiscali:99 scanf:01 fmt:01 3.06:01 bscanf:01 char:01 workarounds:01 tokens:01 chris:01 christophe:01 computed:01 caml:01 int:01 token:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I am trying to understand how Scanf works and have some questions. The comment preceding the definition of [kscanf ib ef fmt f] says If the entire scanning succeeds [...] the tokens are applied to [f]. But are they not applied before? Consider Objective Caml version 3.06+33 (2003-05-19) let f i = print_string "Hello"; print_newline(); fun j k -> i+j+k in let buf = Scanf.Scanning.from_string "3 4 x" in Scanf.bscanf buf "%i %i %i" f;; Hello Exception: Scanf.Scan_failure "scanf: bad input at char number 5: int_of_string". The scanning has not succeeded, however the side effect took place. What am I misunderstanding here? As far as I get it, the first argument is applied when the scanning of the second succeeds since it gives [stack (stack f i) j] and the argument [stack f i] will be computed. If arguments are applied to [f] before the scanning is complete, then what is the purpose of [stack], why not apply them directly instead of waiting for the next token ? Now, is it possible to build objects through a format process? More precisely, I'd like to have a function that takes (something like) a format string, say "%i %f", and creates an object like object method fold : ('a -> int -> float -> 'a) -> 'a -> 'a end It does not look so easy to me since on one hand you would have to parametrize the object to be able to build its type incrementally (e.g. with a (int -> float -> 'a, 'a) type) but that would then forbid the fold method to be fully polymorphic (not really nice...). Is this correct? Are there workarounds? Thanks for comments, ChriS ------------------- 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