caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Goerzen <jgoerzen@complete.org>
To: caml-list@inria.fr
Subject: [Caml-list] Trouble with Toploop
Date: Thu, 6 May 2004 21:42:42 -0500	[thread overview]
Message-ID: <20040507024242.GA13530@complete.org> (raw)

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


                 reply	other threads:[~2004-05-07  2:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040507024242.GA13530@complete.org \
    --to=jgoerzen@complete.org \
    --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).