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 LAA08135; Wed, 23 Jan 2002 11:16:01 +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 LAA07820 for ; Wed, 23 Jan 2002 11:16:00 +0100 (MET) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0NAFxT15559 for ; Wed, 23 Jan 2002 11:15:59 +0100 (MET) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id LAA19561 for caml-list@inria.fr; Wed, 23 Jan 2002 11:15:59 +0100 Date: Wed, 23 Jan 2002 11:15:59 +0100 From: Daniel de Rauglaudre To: Caml List Subject: Re: [Caml-list] beginner question about camlp4 Message-ID: <20020123111559.C17175@verdot.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from doug@bagley.org on Tue, Jan 22, 2002 at 08:45:10PM -0600 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Tue, Jan 22, 2002 at 08:45:10PM -0600, Doug Bagley wrote: > let chan = open_in "file" in > try > begin process chan end; > close chan > with > Ouch -> close chan; maybe_do_something > | e -> close chan; raise e;; No problem about your Camlp4 code, and it is indeed a possible usage of Camlp4. But I would have written a different construction, because I consider than your first "close chan" should be outside the try and I would like to be able to return something (get the result of your "process chan"). My construction would be something like this: some_expression always some_cleanup which would be converted into: let x = try some_expression with e -> some_cleanup; raise e in some_cleanup; x Well, but perhaps an infix construction is not very readable here. > let safely setup cleanup subject f = > let x = setup subject in > try f x; cleanup x with e -> cleanup x; raise e For the same reason, I would prefer: let safely setup cleanup subject f = let x = setup subject in let r = try f x with e -> cleanup x; raise e in cleanup x; r This way, "safely" could return the value of "f x" when it is ok. Now, Camlp4 or function "safely", it is a matter of personal opinion. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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