From: Jeremy Yallop <jeremy.yallop@ed.ac.uk>
To: Vincent Hanquez <tab@snarc.org>
Cc: Jon Harrop <jon@ffconsultancy.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] try .. finally using new camlp4
Date: Mon, 09 Jul 2007 10:43:04 +0100 [thread overview]
Message-ID: <46920328.2080509@ed.ac.uk> (raw)
In-Reply-To: <20070709090131.GA17462@snarc.org>
Vincent Hanquez wrote:
>> EXTEND Gram
>> expr: LEVEL "top"
>> [[ "try"; f=expr; "finally"; g=expr ->
>> <:expr<
>> ((function
>> | `Val v, g -> g(); v
>> | `Exn e, g -> g(); raise e)
>> ((try `Val($f$) with e -> `Exn e), (fun () -> $g$)))
>> >>]];
>> END
>
> I don't know camlp4, but why don't you use a more straightforward
> (let r = try f() with e -> g(); raise e in g(); r) construct
> instead of wrapping/unwrapping the thing into polymorphic variant ?
Jon's version avoids name capture. If the user writes
let r = 1 in
try
2
finally
print_endline (string_of_int r)
then your version (modulo the unit arguments) expands into
let r = 1 in
let r = try 2
with e ->
print_endline (string_of_int r);
raise e in
print_endline (string_of_int r);
r
which prints "2" instead of "1".
Jeremy.
next prev parent reply other threads:[~2007-07-09 9:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-08 0:14 Jon Harrop
2007-07-08 3:28 ` [Caml-list] " Julien Moutinho
2007-07-09 9:01 ` Vincent Hanquez
2007-07-09 9:43 ` Jeremy Yallop [this message]
2007-07-09 9:33 ` Vincent Hanquez
2007-07-09 13:06 ` Nicolas Pouillard
2007-07-10 8:28 ` Bruno De Fraine
2007-07-10 12:44 ` Nicolas Pouillard
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=46920328.2080509@ed.ac.uk \
--to=jeremy.yallop@ed.ac.uk \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.com \
--cc=tab@snarc.org \
/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