From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] beginner question about camlp4
Date: Wed, 23 Jan 2002 11:15:59 +0100 [thread overview]
Message-ID: <20020123111559.C17175@verdot.inria.fr> (raw)
In-Reply-To: <m38zapkcp5.fsf@ns.bagley.org>; from doug@bagley.org on Tue, Jan 22, 2002 at 08:45:10PM -0600
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
next prev parent reply other threads:[~2002-01-23 10:16 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 [this message]
2002-01-23 19:43 ` Charles Martin
2002-01-23 20:00 ` Doug Bagley
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=20020123111559.C17175@verdot.inria.fr \
--to=daniel.de_rauglaudre@inria.fr \
--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