Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-05-07 (02:42)
From: John Goerzen <jgoerzen@c...>
Subject: [Caml-list] Trouble with Toploop

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

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
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 <>             

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: