From: "Harrison, John R" <john.r.harrison@intel.com>
To: Zheng Li <zheng_li@users.sourceforge.net>
Cc: OCaml <caml-list@yquem.inria.fr>
Subject: RE: Stricter version of #use ?
Date: Tue, 24 Mar 2009 17:14:20 -0700 [thread overview]
Message-ID: <BC67582D4FC8ED45BAABE48343BF5711033C6147A8@azsmsx501.amr.corp.intel.com> (raw)
In-Reply-To: <49C95DC0.9020605@users.sourceforge.net>
Hi Zheng,
| 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).
Thanks, that's a clever solution! Just one more question, though. I'd
like to exploit this alternative "use" function in a slightly more
programmatic way so I also want it as an OCaml function. (Then I can
search non-standard paths, do basic conditional loading etc.) So I
adapted your solution slightly and put the following in my .ocamlinit
file to give myself a function "use_file" that (so I thought) would
correspond to the #use directive:
let use_file =
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
(Format.print_string("Error in included file "^name);
Format.print_newline();
raise Exit)
else ();;
Hashtbl.replace Toploop.directive_table "use"
(Toploop.Directive_string use_file);;
So with my "root.ml" and "branch.ml" files from the first message, it
all works exactly as I wanted, a nice early failure with a clear
"traceback":
# #use "root.ml";;
val x : int = 1
val u : int = 3
Exception: Failure "X".
Error in included file branch.ml
# x;;
- : int = 1
# u;;
- : int = 3
Yet if I replace the line
#use "branch.ml";;
in "root.ml" with what I supposed would be equivalent:
use_file "branch.ml";;
then the exception propagates out and I get the "rollback" that
I wanted to avoid:
# #use "root.ml";;
val x : int = 1
val u : int = 3
Exception: Failure "X".
Error in included file branch.ml
Exception: Pervasives.Exit.
# x;;
- : int = 1
# u;;
Unbound value u
Any idea why that should be?
John.
next prev parent reply other threads:[~2009-03-25 0:14 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
2009-03-25 0:14 ` Harrison, John R [this message]
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=BC67582D4FC8ED45BAABE48343BF5711033C6147A8@azsmsx501.amr.corp.intel.com \
--to=john.r.harrison@intel.com \
--cc=caml-list@yquem.inria.fr \
--cc=zheng_li@users.sourceforge.net \
/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