caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hongbo Zhang <bobzhang1988@gmail.com>
To: Jean-Baptiste Jeannin <jeannin@cs.cornell.edu>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] Re: Returning an element computed with Toploop
Date: Tue, 10 Jul 2012 22:42:34 -0400	[thread overview]
Message-ID: <4FFCE81A.80700@gmail.com> (raw)
In-Reply-To: <A7FC6DE86AF33142A1FA4CE04EEBF4F18591C61822@gobo.cs.cornell.edu>

On 7/10/12 11:08 AM, Jean-Baptiste Jeannin wrote:
> Hello all,
>
Hi,
> Thanks to Jonathan Kimmitt on this mailing list, I learned about the existence of the Toploop module, that allows to execute OCaml code from a string. For example, one can do:
>
> # Toploop.execute_phrase true Format.err_formatter
> ((!Toploop.parse_toplevel_phrase) (Lexing.from_string "355./.113.;;"));;
> - : float = 3.14159292035398252
> - : bool = true
>
Use Tooploop.getvalue.
> However I could not find any official documentation of the module on the internet. In particular, the example above only prints out what was computed and returns a boolean (true or false), depending on how the computation terminated. I would like to compute an element and get the element back to be able to use it later in the computation. Is that possible and how could I do it?
>
The codebase for toplevel/ is pretty small, IMHO, reading the source is 
best way to understand how toploop works.

There's another non-trivial example in camlp4/Camlp4Top which shows you 
how to customize toplevel. If you understand how it works, feel free to 
use it, it's pretty safe :-)
> Thanks a lot,
> Jean-Baptiste
>



      parent reply	other threads:[~2012-07-11  2:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-10 15:08 [Caml-list] " Jean-Baptiste Jeannin
2012-07-10 20:50 ` Edgar Friendly
2012-07-11  2:42 ` Hongbo Zhang [this message]

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=4FFCE81A.80700@gmail.com \
    --to=bobzhang1988@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=jeannin@cs.cornell.edu \
    /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).