caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Emmanuel.Chailloux@pps.jussieu.fr (Emmanuel Chailloux)
To: caml-list@inria.fr
Subject: [Caml-list] loading files in toplevel
Date: Tue, 24 Jul 2001 15:38:31 +0200	[thread overview]
Message-ID: <200107241338.f6ODcVF23595@foobar.pps.jussieu.fr> (raw)


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


             reply	other threads:[~2001-07-24 13:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-24 13:38 Emmanuel Chailloux [this message]
2001-08-24 14:02 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=200107241338.f6ODcVF23595@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;
as well as URLs for NNTP newsgroup(s).