caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Trouble with Toploop
@ 2004-05-07  2:42 John Goerzen
  0 siblings, 0 replies; only message in thread
From: John Goerzen @ 2004-05-07  2:42 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-05-07  2:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-07  2:42 [Caml-list] Trouble with Toploop John Goerzen

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