Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] beginner question about camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] beginner question about camlp4
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