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 QAA20500; Thu, 24 Jan 2002 16:52:30 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA20628 for caml-list@pauillac.inria.fr; Thu, 24 Jan 2002 16:52:29 +0100 (MET) 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 VAA22857 for ; Wed, 23 Jan 2002 21:00:56 +0100 (MET) Received: from ns.bagley.org (ns.bagley.org [216.30.46.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0NK0tT06566 for ; Wed, 23 Jan 2002 21:00:55 +0100 (MET) Received: by ns.bagley.org (TRS/80 Mail Daemon, from userid 500) id 76796FBA57; Wed, 23 Jan 2002 14:00:55 -0600 (CST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15439.5751.37201.475994@ns.bagley.org> Date: Wed, 23 Jan 2002 14:00:55 -0600 To: Charles Martin Cc: Caml List Subject: Re: [Caml-list] beginner question about camlp4 From: Doug Bagley Organization: Ewige Blumenkraft AG X-Face: "|NaWfYJ-]P="T#?R.9}QgGuFXUd@3vi[.E2q-;"NV3+k_y@zreL2w^ts0XPXtt9^9{uQ@.cu2GgUgK9@HXC\a}Rtah}0'eT~>or7[~Hd?;!\Bpo#"3w>0a0ft-MvvZ In-Reply-To: <5.1.0.14.0.20020123113751.022f34c0@pop.mail.yahoo.com> References: <5.1.0.14.0.20020123113751.022f34c0@pop.mail.yahoo.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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