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=1.0 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 53F06BBAF for ; Tue, 24 Mar 2009 23:23:57 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwCACP6yEnUGyoElGdsb2JhbACVaAEBAQEJCwgJEQO8c4N2Bg X-IronPort-AV: E=Sophos;i="4.38,415,1233529200"; d="scan'208";a="37141520" Received: from smtp4-g21.free.fr ([212.27.42.4]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Mar 2009 23:23:55 +0100 Received: from smtp4-g21.free.fr (localhost [127.0.0.1]) by smtp4-g21.free.fr (Postfix) with ESMTP id 8CA964C8078; Tue, 24 Mar 2009 23:23:49 +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 97A794C802B; Tue, 24 Mar 2009 23:23:47 +0100 (CET) Message-ID: <49C95DC0.9020605@users.sourceforge.net> Date: Tue, 24 Mar 2009 23:25:04 +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: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; val:01 val:01 semantics:01 semantics:01 camlp:01 camlp:01 ad-hoc:01 recursive:01 compiler:01 toplevel:01 hashtbl:01 toploop:01 toploop:01 2009:98 sourceforge:01 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