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.9 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id E318EBBAF for ; Wed, 25 Mar 2009 09:31:43 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArsBAN6IyUnUGyoElGdsb2JhbACVaAEBAQEJCwgJEQO8eIN2Bg X-IronPort-AV: E=Sophos;i="4.38,418,1233529200"; d="scan'208";a="26270562" Received: from smtp4-g21.free.fr ([212.27.42.4]) by mail1-smtp-roc.national.inria.fr with ESMTP; 25 Mar 2009 09:31:43 +0100 Received: from smtp4-g21.free.fr (localhost [127.0.0.1]) by smtp4-g21.free.fr (Postfix) with ESMTP id C912B4C807F; Wed, 25 Mar 2009 09:31:37 +0100 (CET) Received: from [192.168.17.1] (ivr94-8-88-162-26-239.fbx.proxad.net [88.162.26.239]) by smtp4-g21.free.fr (Postfix) with ESMTP id CDF514C8020; Wed, 25 Mar 2009 09:31:34 +0100 (CET) Message-ID: <49C9EC36.6020007@users.sourceforge.net> Date: Wed, 25 Mar 2009 09:32:54 +0100 From: Zheng Li User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4pre) Gecko/20090323 Lightning/1.0pre Shredder/3.0b3pre MIME-Version: 1.0 To: "Harrison, John R" Cc: OCaml Subject: Re: Stricter version of #use ? References: <49C95DC0.9020605@users.sourceforge.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; traceback:01 val:01 val:01 pervasives:01 toplevel:01 toplevel:01 afaik:01 2009:98 sourceforge:01 unbound:01 wrote:01 exception:01 exception:01 int:01 int:01 Hi John, On 3/25/2009 1:14 AM, Harrison, John R wrote: > 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? The execution difference between a toplevel phrase like "use_file xxx" and a toplevel directive like "#use xxx" is subtle. The current toplevel implementation always execute a toplevel phrase in a protected environment, i.e. the execution effect of a single toplevel phrase is always all-or-nothing. And this is, AFAIK, hard-wired in the code and I don't know how to tweak it without modifying the toplevel source. On the other hand, the toplevel won't protect the execution of a directive, rather it relies on the directives to protect themselves --- that's why we can still do some little trick without modifying the toplevel source. So in the end, you can't partly keep the execution effect of a toplevel phrase like "use_file xxx". Moreover, I can't see how we can avoid this (if we intend to use "use_file" as a function rather than a directive), no matter how we define "use_file". If the "use_file" fails upon some inside errors, the whole effect of its execution will be aborted due to the protected environment; if we catch the errors ourselves, i.e. the whole execution still returns successfully despite the inside error, then the rest of the code (below "use_file xxx") will continue to run. The only solution (without modifying toplevel) is to define "use_file" as a function always succeeds and returns a flag telling whether the execution is all successful. Then it will be the responsibility of programmers to decide to abort or continue or reset. Something like: val use_file: string -> (unit -> unit) option it returns either None on full success or Some reset to let the programmers choose whether to abort (raise Exit) or (reset ()). Regards -- Zheng