Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Trouble with Toploop
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Goerzen <jgoerzen@c...>
Subject: [Caml-list] Trouble with Toploop
Hello,

I am having trouble making Toploop.setvalue do the right thing.  Here is
an example:

Toploop.initialize_toplevel_env();;
let apv = 5;;
Toploop.setvalue "apv" (Obj.repr apv);;

let eval txt = let lb = (Lexing.from_string txt) in
  let phr = !Toploop.parse_toplevel_phrase lb in
    Toploop.execute_phrase true Format.std_formatter phr;;

eval "let add1 x = x +1;;";;
eval "add1 2;;";;
eval "let y = 42;;";;

print_int (Obj.obj (Toploop.getvalue "y"));;
print_endline "";;
print_int (Obj.obj (Toploop.getvalue "apv"));;
print_endline "";;
eval "add1 apv;;";;
eval "apv;;";;

When I run this, I get:

val add1 : int -> int = <fun>
- : int = 3
val y : int = 42
42
5
Fatal error: exception Typecore.Error(_, _)

(Note that the eval "apv;;" would give the same error.)

So, I get set a value.  I can later get it back with getvalue.  I can
also use getvalue to give me values that were set entirely within the
toploop environment.  But I cannot use a value I have set with setvalue
in any calculation.

Any suggestions?

-- 
John Goerzen <jgoerzen@complete.org>                       www.complete.org

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners