From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA01682; Fri, 24 Aug 2001 15:56:41 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA01860 for ; Fri, 24 Aug 2001 15:56:40 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f7ODuej05888 for ; Fri, 24 Aug 2001 15:56:40 +0200 (MET DST) Received: from foobar.pps.jussieu.fr (IDENT:root@foobar.pps.jussieu.fr [134.157.168.2]) by shiva.jussieu.fr (8.11.3/jtpda-5.3.3) with ESMTP id f7ODudO52434 for ; Fri, 24 Aug 2001 15:56:40 +0200 (CEST) Received: from chrome (chrome.pps.jussieu.fr [134.157.168.24]) by foobar.pps.jussieu.fr (8.11.0/jtpda-5.3.2) with ESMTP id f7OE0la15971 ; Fri, 24 Aug 2001 16:00:47 +0200 Message-Id: <200108241400.f7OE0la15971@foobar.pps.jussieu.fr> Date: Fri, 24 Aug 2001 16:02:16 +0200 From: Emmanuel.Chailloux@pps.jussieu.fr Content-Type: text/plain; format=flowed; charset=us-ascii X-Mailer: Apple Mail (2.388) Cc: Emmanuel.Chailloux@pps.jussieu.fr To: caml-list@inria.fr Mime-Version: 1.0 (Apple Message framework v388) Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] loading files in toplevel Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, One month ago, I posted a question about loading files in toplevel. My goal was to write functions to select files to load : let choose x = if x < 0 then load "f1.ml" else load "f2.ml";; with f1.ml : let f1_succ x = x + 1;; f2.ml : let f2_succ x = x + 1;; I wrote the following "load" function : let load file = Topdirs.dir_use Format.std_formatter file;; which seems to run : # choose 2;; val f2_succ : int -> int = - : unit = () but the global symbol f2_succ was unknown at the toplevel. # f2_succ;; Unbound value f2_succ After my vacations, I modified the Toploop.execute_phrase in the following way ( only 2 lines : (* MODIF *) ) : -------- let execute_phrase print_outcome ppf phr = match phr with | Ptop_def sstr -> (* MODIF *) let oldenv = !toplevel_env in let (str, sg, newenv) = Typemod.type_structure !toplevel_env sstr in let lam = Translmod.transl_toplevel_definition str in Warnings.check_fatal (); let res = load_lambda ppf lam in begin match res with | Result v -> if print_outcome then begin match str with | [Tstr_eval exp] -> fprintf ppf "@[- : %a@ =@ %a@]@." Printtyp.type_scheme exp.exp_type (print_value newenv v) exp.exp_type | [] -> () | _ -> fprintf ppf "@[%a@]@." (print_items newenv) sg end; (* MODIF *) if oldenv <> newenv then toplevel_env := newenv; true .... ------------ and my old "load" function runs now : # load "f2.ml";; val f2_succ : int -> int = # f2_succ;; - : int -> int = This small modification can be integrated inside the future ocaml distribution ? Best regards. Emmanuel... ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr