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 NAA17196; Wed, 24 Apr 2002 13:16:40 +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 NAA17157 for ; Wed, 24 Apr 2002 13:16:39 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3OBGaP11074 for ; Wed, 24 Apr 2002 13:16:37 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id UAA06573; Wed, 24 Apr 2002 20:16:16 +0900 (JST) To: chrzaszcz@mimuw.edu.pl Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to read three integers from a text-file... ? In-Reply-To: <15557.14957.358556.545541@absurd.mimuw.edu.pl> References: <15557.14957.358556.545541@absurd.mimuw.edu.pl> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020424201616Z.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 24 Apr 2002 20:16:16 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Jacek Chrzaszcz > Is there a clean way (a one-liner) to read a constant number of > integers separated by whitespace from a text-file (or stdin) ? > > I mean something like > scanf("%d%d%d",&a,&b,&c) in C, or > readln(a,b,c) in Pascal A clean way to do this is to use then Genlex module. # #load"camlp4o.cma";; # open Genlex;; # let s = Genlex.make_lexer [] (Stream.of_channel stdin);; val s : Genlex.token Stream.t = # match s with parser [< 'Int x; 'Int y; 'Int z >] -> (x, y, z);; 3 5 7 - : int * int * int = 3, 5, 7 If you don't want to use camlp4o.cma, it is possible with Stream.next, but a bit more painful. Cheers, Jacques Garrigue ------------------- 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