caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: verlyck <Bruno.Verlyck@inria.fr>
From: Bruno.Verlyck@inria.fr
To: kirillkh <kirillkh@gmail.com>
Cc: bhurt@janestcapital.com, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] best and fastest way to read lines from a file?
Date: Tue,  2 Oct 2007 19:10:30 +0200 (CEST)	[thread overview]
Message-ID: <20071002171030.97D161FA302@macchabee.inria.fr> (raw)
In-Reply-To: <e2d02be30710020915y2f115359j3151c8d36aa2c3e8@mail.gmail.com> (kirillkh@gmail.com)

   Date: Tue, 2 Oct 2007 18:15:57 +0200
   From: kirillkh <kirillkh@gmail.com>
Hi,
   > This should be a FAQ.
   Since we're talking of 10+ lines of code and only one case among
   many possible (you might also want to do something fairly similar,
   but not quite the same, as iterating over all words or characters
   in a file, doing something else than counting, etc.), I would
   rather see it implemented in a library as combinator.  What I have
   in mind is a function that goes over a file and invokes some user
   code on each block of bytes/characters/lines/words/... The points
   of customization would be:
   * how to detect the start and end of block
   * routine to pass the blocks to

   Then, on top of this combinator, build block-specific ones: for
   byte, char, line, word blocks.  Also make it possible to customize
   buffering behavior.

   Being new to OCaml, I'm interested in comments; is what I suggest a
   good idea?
Yes, why not ?

   If yes, why hasn't anyone implemented it yet?  
I believe Cash (in the Hump:
 http://caml.inria.fr/cgi-bin/hump.fr.cgi?contrib=86) 
has some of the things you ask for: look around fold_in_channel (as a
combinator; yes, it *is* 5 lines of code), and for what you call
blocks, chapters 6 & 7 of the documentation (Reading delimited strings
& Record I/O and field parsing).  Buffering is also parameterizable
(between 1 and 4Kb, no line buffering, sorry, too much C code to
modify in the Ocaml runtime).

It may not suit your taste, but when generalizing, everybody tends to
have one's own very specific idea of how to do it.  Human nature...
At least Cash can give you some ideas.

Of course, the OP was asking for the fastest way...  OK, we aren't
anymore.

HTH,
Bruno.

Disclaimer: Cash is still not ported to Ocaml 3.10; but 3.09 is fine.
Have to choose: camlp4 or 5... ?


  reply	other threads:[~2007-10-02 17:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-01 21:27 YC
2007-10-01 21:55 ` [Caml-list] " Daniel Bünzli
2007-10-01 22:29   ` YC
2007-10-01 21:55 ` Olivier Roussel
2007-10-02 12:39   ` Mattias Engdegård
2007-10-02 12:56     ` Brian Hurt
2007-10-02 16:15       ` kirillkh
2007-10-02 17:10         ` verlyck, Bruno.Verlyck [this message]
2007-10-02 18:02         ` kirillkh
2007-10-02 19:35           ` skaller
2007-10-02 21:05             ` kirillkh
2007-10-02 21:07               ` Jon Harrop
2007-10-02 20:23           ` Olivier Andrieu
2007-10-02 20:49             ` kirillkh
2007-10-02 21:10               ` Jon Harrop
2007-10-02 21:15               ` David Allsopp
2007-10-02 22:23                 ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071002171030.97D161FA302@macchabee.inria.fr \
    --to=bruno.verlyck@inria.fr \
    --cc=bhurt@janestcapital.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=kirillkh@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).