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 QAA24293; Mon, 2 Feb 2004 16:33:42 +0100 (MET) 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 QAA23631 for ; Mon, 2 Feb 2004 16:33:41 +0100 (MET) Received: from VIRUSWALL (mail.biovision.de [212.59.36.67]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id i12FXeP14401 for ; Mon, 2 Feb 2004 16:33:40 +0100 (MET) Received: from 192.168.43.51 by VIRUSWALL (InterScan E-Mail VirusWall NT); Mon, 02 Feb 2004 16:33:03 +0100 Received: by EXS_BDC with Internet Mail Service (5.5.2655.55) id ; Mon, 2 Feb 2004 16:33:43 +0100 Message-ID: From: "Khamenia, Valery" To: "'Richard Jones'" , "Khamenia, Valery" Cc: "'caml-list@inria.fr'" Subject: AW: [Caml-list] laconical input from a file for arrays and/or mat rices Date: Mon, 2 Feb 2004 16:33:39 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2655.55) Content-Type: text/plain; charset="iso-8859-1" X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 cin:99 cin:99 buffer:01 buffer:01 char:01 stdin:01 printf:01 printf:01 error-prone:01 stdin:01 stdout:01 stateful:01 ocaml-list:01 2004.:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Rich and all, > Probably not quite what you want, but I have a library for reading and > writing comma-separated values (CSV) files here: > http://www.merjis.com/developers/csv/ > http://www.merjis.com/developers/csv/ocaml-csv-1.0.1.tar.gz thank you, it would be interesting what's the skeleton idea behind your code, but I can't get it after first apporoach :) Actually, to emulate behaviour of C++ expression "cin >> mydoublevar" I use function cin_float instead of read_float: (* ---------- START -----------*) exception EOF of string let max = 4096 let buf = String.create max and wbuf = Buffer.create 64 and cin_float_i = ref 0 and cin_float_n = ref 0 let rec scan_words i n inword = if i < n then let c = buf.[i] in if c!=' ' && c!='\n' && c != '\t' then begin Buffer.add_char wbuf c; scan_words (i + 1) n true end else if inword then begin let word = Buffer.contents wbuf in Buffer.clear wbuf; cin_float_i:=i+1; cin_float_n:=n; float_of_string word end else scan_words (i + 1) n false else let nread = input stdin buf 0 max in if nread <> 0 then scan_words 0 nread inword else raise (EOF "reading after the end of file");; let cin_float() = scan_words (!cin_float_i) (!cin_float_n) false;; (* test: Printf.printf "%f %f " (cin_float()) (cin_float()); *) (* ---------- START -----------*) However it is error-prone even for single-thread applications. Indeed, after call of cin_float some symbols could megrate from stdin into the buffer "buf". For this reason in the client code after calling "cin_float" the functions like "read_float()" will not find all those symbols which have been moved into my buffer already. Decentralized buffers :( Now, "read_float" is actually a composition: float_of_string (read_line()) and "read_line" is just flush_stdout; input_line stdin Thus, to avoid non-decentralized buffers one should access stateful "stdin" channel. Is "stdin" object in OCaML standardized?.. Maybe you, Rich, have a better idea. P.S. BTW, I was impressed by a spam level in ocaml-list in Jan 2004. Why posts are not allowed only for a subscribers (or even better for veryfied emails) ?.. -- vak ------------------- 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