From: Zheng Li <zheng_li@users.sourceforge.net>
To: "Harrison, John R" <john.r.harrison@intel.com>
Cc: OCaml <caml-list@yquem.inria.fr>
Subject: Re: Stricter version of #use ?
Date: Tue, 24 Mar 2009 23:25:04 +0100 [thread overview]
Message-ID: <49C95DC0.9020605@users.sourceforge.net> (raw)
In-Reply-To: <BC67582D4FC8ED45BAABE48343BF5711033C59A678@azsmsx501.amr.corp.intel.com>
Hi,
On 3/24/2009 7:00 PM, Harrison, John R wrote:
> Then I want the following to stop immediately on the failure inside
> "branch.ml" and hence not evaluate the "y = 2" line in "root.ml" as it
> currently does:
>
> Objective Caml version 3.10.0
>
> # #use "root.ml";;
> val x : int = 1
> val u : int = 3
> Exception: Failure "X"
> val y : int = 2
I agree this doesn't look like an intuitive semantics.
> On the other hand, I'd want it to keep the results of the x = 1 and
> u = 3 lines, not roll back everything. Is this easy to accomplish?
I just want to say rolling back everything is another
consistent/intuitive semantics.
> (By the way, I'm ultimately interested in using this together with
> camlp5, and possibly with the new camlp4, if that makes a difference.)
You may try the following code snippet. It's not a total solution but an
ad-hoc workaround. It only deals with recursive "#use" like in your
example (e.g., "#load" operation inside a "#use" script will still
behave the same as before), though it's not difficult to adapt the other
primitives similarly ("#load" is probably the only one wanted, let me
know if you need any help on that).
The only advantage of this method is that you don't have to modify the
compiler code. You can just copy&paste the code into your toplevel
sessions and go, or add it into your .ocamlinit file if you need it all
the time.
----
Hashtbl.replace Toploop.directive_table "use"
(Toploop.Directive_string begin
let is_top = ref true in
fun name ->
let top_env = !is_top in
is_top := false;
let succ = Toploop.use_file Format.std_formatter name in
is_top := top_env;
if not !is_top && not succ then raise Exit
end)
----
HTH.
--
Zheng
next prev parent reply other threads:[~2009-03-24 22:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 18:00 Harrison, John R
2009-03-24 22:25 ` Zheng Li [this message]
2009-03-25 0:14 ` Harrison, John R
2009-03-25 8:32 ` Zheng Li
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=49C95DC0.9020605@users.sourceforge.net \
--to=zheng_li@users.sourceforge.net \
--cc=caml-list@yquem.inria.fr \
--cc=john.r.harrison@intel.com \
/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