caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Doug Bagley <doug@bagley.org>
To: Charles Martin <joelisp@yahoo.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] beginner question about camlp4
Date: Wed, 23 Jan 2002 14:00:55 -0600	[thread overview]
Message-ID: <15439.5751.37201.475994@ns.bagley.org> (raw)
In-Reply-To: <5.1.0.14.0.20020123113751.022f34c0@pop.mail.yahoo.com>

Charles Martin wrote:
> let protect f always =
>   try let r = f () in always (); r
>   with e -> always (); raise e
>
> For file handling, I then use the following:
> 
> let with_input_file fname f =
>   let chan = open_in fname in
>   protect (f chan) (fun () -> close_in chan)

Are you sure that's right?  I think (f chan) executes before the call
to protect, and you want protect to execute f:

let with_input_file fname f =
  let chan = open_in fname in
  protect (fun () -> f chan)
     (fun () -> prerr_endline ("closing " ^ fname); close_in chan)

???

I have also developed similar "with_input_from" kind of functions, but
I use Unix.dup/dup2 to switch out the filedescriptors so the functions
that run under them can just read/write from stdin/stdout, instead of
needing a specific channel.  Seems like a common idiom, is it from
lisp?  I forget.  You're welcome to look at my versions here:

 http://www.bagley.org/~doug/ocaml/io_lib/

Of course, maybe I'm the one who is not doing it right.

cheers,
doug
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2002-01-24 15:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-23  2:45 Doug Bagley
2002-01-23 10:15 ` Daniel de Rauglaudre
2002-01-23 19:43 ` Charles Martin
2002-01-23 20:00   ` Doug Bagley [this message]
2002-01-23 21:48     ` Charles Martin

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=15439.5751.37201.475994@ns.bagley.org \
    --to=doug@bagley.org \
    --cc=caml-list@inria.fr \
    --cc=joelisp@yahoo.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).