From: Emmanuel.Chailloux@pps.jussieu.fr
To: caml-list@inria.fr
Cc: Emmanuel.Chailloux@pps.jussieu.fr
Subject: Re: [Caml-list] loading files in toplevel
Date: Fri, 24 Aug 2001 16:02:16 +0200 [thread overview]
Message-ID: <200108241400.f7OE0la15971@foobar.pps.jussieu.fr> (raw)
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 = <fun>
- : 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 "@[<v>%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 = <fun>
# f2_succ;;
- : int -> int = <fun>
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
next reply other threads:[~2001-08-24 13:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-24 14:02 Emmanuel.Chailloux [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-07-24 13:38 Emmanuel Chailloux
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=200108241400.f7OE0la15971@foobar.pps.jussieu.fr \
--to=emmanuel.chailloux@pps.jussieu.fr \
--cc=caml-list@inria.fr \
/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