Browse thread
[Caml-list] loading files in toplevel
- Emmanuel.Chailloux@p...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Emmanuel.Chailloux@p... |
| Subject: | [Caml-list] loading files in toplevel |
Hello,
For on-line applications, I want to write a function load : string -> unit
which loads ml files in the O'Caml toplevel. For example :
let choose x = if x < 0 then load "f1.ml" else load "f2.ml";;
with
f1.ml :
let f1_succ x = x + 1;;
and
f2.ml :
let f2_succ x = x + 1;;
My first try was :
let load file = Topdirs.dir_use Format.std_formatter file;;
# choose 1;;
==>
val f2_succ : int -> int = <fun>
- : unit = ()
# choose (-1);;
==>
val f1_succ : int -> int = <fun>
- : unit = ()
BUT I can't acces to the global symbol f1_succ :
# f1_succ;;
==>
Unbound value f1_succ
This symbol belongs to the toplevel environment :
# Toploop.getvalue "f1_succ";;
==>
- : Obj.t = <abstr>
And this is the good definition :
# ( (Obj.obj (Toploop.getvalue "f1_succ")) : int -> int) 1;;
==>
- : int = 2
When I trace the function "Toploop.execute_phrase" :
# #trace Toploop.execute_phrase;;
==>
Toploop.execute_phrase is now traced.
the trace output is visible when I use my function "load" but not when I use
the directive "#use".
# load "f1.ml";;
Toploop.execute_phrase <-- true
Toploop.execute_phrase --> <fun>
Toploop.execute_phrase* <-- <abstr>
Toploop.execute_phrase* --> <fun>
Toploop.execute_phrase** <-- <abstr>
val f1_succ : int -> int = <fun>
Toploop.execute_phrase** --> true
- : unit = ()
# f1_succ;;
Unbound value f1_succ
# #use "f1.ml";;
val f1_succ : int -> int = <fun>
# f1_succ;;
- : int -> int = <fun>
When I read the files toplevel/toploop.ml and toplevel/topdirs.ml from the
distribution (3.01) I don't understand why the directive "#use" doesn't call
Toploop.execute_phrase.
Is there a special mode for the directives?
Have you any idea?
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