From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id AF877BC20 for ; Wed, 25 Mar 2009 01:14:21 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnMCAGMUyUnANzRYkWdsb2JhbACVZwEBAQEJCwoHEQW8MIN2Bg X-IronPort-AV: E=Sophos;i="4.38,415,1233529200"; d="scan'208";a="24918395" Received: from mga01.intel.com ([192.55.52.88]) by mail3-smtp-sop.national.inria.fr with ESMTP; 25 Mar 2009 01:14:20 +0100 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 24 Mar 2009 17:06:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.38,415,1233561600"; d="scan'208";a="441750645" Received: from unknown (HELO azsmsx601.amr.corp.intel.com) ([10.2.121.193]) by fmsmga002.fm.intel.com with ESMTP; 24 Mar 2009 17:09:42 -0700 Received: from azsmsx501.amr.corp.intel.com ([10.2.167.99]) by azsmsx601.amr.corp.intel.com ([10.2.121.193]) with mapi; Tue, 24 Mar 2009 17:14:18 -0700 From: "Harrison, John R" To: Zheng Li Cc: OCaml Date: Tue, 24 Mar 2009 17:14:20 -0700 Subject: RE: Stricter version of #use ? Thread-Topic: Stricter version of #use ? Thread-Index: AcmszzsQ15GTBVfLQ1aDFZlMrghvFQADvpkg Message-ID: References: <49C95DC0.9020605@users.sourceforge.net> In-Reply-To: <49C95DC0.9020605@users.sourceforge.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam: no; 0.00; ad-hoc:01 recursive:01 programmatic:01 ocaml:01 non-standard:01 toploop:01 hashtbl:01 toploop:01 traceback:01 val:01 val:01 pervasives:01 unbound:01 exception:01 exception:01 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 =3D let is_top =3D ref true in fun name -> let top_env =3D !is_top in is_top :=3D false; let succ =3D Toploop.use_file Format.std_formatter name in is_top :=3D top_env; if not !is_top && not succ then (Format.print_string("Error in included file "^name); Format.print_newline(); raise Exit) else ();; =20 Hashtbl.replace Toploop.directive_table "use" (Toploop.Directive_string use_file);; =20 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 =3D 1 val u : int =3D 3 Exception: Failure "X". Error in included file branch.ml # x;; - : int =3D 1 # u;; - : int =3D 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 =3D 1 val u : int =3D 3 Exception: Failure "X". Error in included file branch.ml Exception: Pervasives.Exit. # x;; - : int =3D 1 # u;; Unbound value u Any idea why that should be? John.