caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Better option to read a file
Date: Wed, 17 Mar 2004 14:48:07 +1100	[thread overview]
Message-ID: <20040317034807.GA25205@pulp.anu.edu.au> (raw)
In-Reply-To: <E2DFEE92-7790-11D8-938F-000393B21E00@ctima.uma.es>


what's about ....

let file_ch = (open_in input_file) in
let read_lines =
    let read_new_line n =
        try Some (input_line file_ch)
        with End_of_file -> None
    in
        Stream.from read_new_line
in
let rec get_line () = 
    match Stream.next read_lines with
    |s when Str.string_match (Str.regexp "^[\n\t ]+$") s 0 -> get_line ()
    |s -> s
in

p

On Tue, Mar 16, 2004 at 10:28:37PM +0100, Agust?n Valverde wrote:
> Hi
> 
> In a program  I need to read the input data from a file and I have 
> written several options. I want to obtain the string of characters from 
> a text file and I don't know what is the better option. Among others, I 
> have written the following:
> 
> First option:
> 
> let leer_file fl =
>      let form = ref "" in
>      let arch = open_in fl in
>      let long = in_channel_length arch in
>      form := String.create (long-1);
>      really_input arch (!form) 0 (long-1);
>      close_in arch;
>      !form;;
> 
> Second:
> 
> let rec unir c ac = unir ac^(Char.escaped c);;
> 
> let leer2 fl =
>      let form = ref "" in
>      let c = ref '-' in
>      let arch = open_in fl in
>      (try
>        (while true do (c := input_char arch); (if !c != '\n' then (form 
> := unir !c !form) else ()) done)
>      with End_of_file -> close_in arch);
>      !form;;
> 
> I also have a parser to convert the string, could I to improve these 
> functions merging them with the parser in some way?
> 
> Thanks for your help
> 
> Agust?n Valverde
> Department of Applied Mathematics
> University of Malaga, Spain
> 
> -------------------
> 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

-- 
++ If you have an apple and I have an apple and we  exchange apples 
   then you and I will still each have one apple. But if you have 
   an idea and I have an idea and we exchange these ideas, then each 
   of us will have two ideas. -- George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html

-------------------
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


  reply	other threads:[~2004-03-17  3:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-16 21:28 Agustín Valverde
2004-03-17  3:48 ` Pietro Abate [this message]
2004-03-17  7:31 ` Christoph Bauer
2004-03-17 16:42   ` Agustin Valverde Ramos
2004-03-17 17:46     ` Markus Mottl
2004-03-17 18:20       ` Agustin Valverde Ramos
2004-03-17 18:54         ` Markus Mottl
2004-03-17  8:22 ` Jean-Christophe Filliatre
2004-03-17 10:11   ` Markus Mottl
  -- strict thread matches above, loose matches on Subject: below --
2004-03-16 20:38 Agustín Valverde

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=20040317034807.GA25205@pulp.anu.edu.au \
    --to=pietro.abate@anu.edu.au \
    --cc=caml-list@inria.fr \
    /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).