caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Returning an element computed with Toploop
@ 2012-07-10 15:08 Jean-Baptiste Jeannin
  2012-07-10 20:50 ` Edgar Friendly
  2012-07-11  2:42 ` [Caml-list] " Hongbo Zhang
  0 siblings, 2 replies; 3+ messages in thread
From: Jean-Baptiste Jeannin @ 2012-07-10 15:08 UTC (permalink / raw)
  To: caml-list

Hello all,

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

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?

Thanks a lot,
Jean-Baptiste

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Returning an element computed with Toploop
  2012-07-10 15:08 [Caml-list] Returning an element computed with Toploop Jean-Baptiste Jeannin
@ 2012-07-10 20:50 ` Edgar Friendly
  2012-07-11  2:42 ` [Caml-list] " Hongbo Zhang
  1 sibling, 0 replies; 3+ messages in thread
From: Edgar Friendly @ 2012-07-10 20:50 UTC (permalink / raw)
  To: caml-list

On 07/10/2012 11:08 AM, Jean-Baptiste Jeannin wrote:
> Hello all,
>
> 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
>
> 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?
>
> Thanks a lot,
> Jean-Baptiste
>
The documentation for Toploop may not be on the net nicely anywhere; 
here's the best link I have: 
https://github.com/thelema/ocaml-community/blob/origin/toplevel/toploop.mli

As far as your problem, you want the `Toploop.getvalue` function; for an 
example, see http://pleac.sourceforge.net/pleac_ocaml/packagesetc.html 
specifically the section "Referring to Packages Indirectly".  Be warned 
that the results are quite type unsafe.

E.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Caml-list] Re: Returning an element computed with Toploop
  2012-07-10 15:08 [Caml-list] Returning an element computed with Toploop Jean-Baptiste Jeannin
  2012-07-10 20:50 ` Edgar Friendly
@ 2012-07-11  2:42 ` Hongbo Zhang
  1 sibling, 0 replies; 3+ messages in thread
From: Hongbo Zhang @ 2012-07-11  2:42 UTC (permalink / raw)
  To: Jean-Baptiste Jeannin; +Cc: caml-list

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
>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-11  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-10 15:08 [Caml-list] Returning an element computed with Toploop Jean-Baptiste Jeannin
2012-07-10 20:50 ` Edgar Friendly
2012-07-11  2:42 ` [Caml-list] " Hongbo Zhang

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