caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Re: caml-list Digest Wed, 11 Jul 2012
       [not found] <20120711100008.A0D467ED34@sympa.inria.fr>
@ 2012-07-11 11:18 ` Kimmitt, Jonathan Richard Robert (Student)
  0 siblings, 0 replies; only message in thread
From: Kimmitt, Jonathan Richard Robert (Student) @ 2012-07-11 11:18 UTC (permalink / raw)
  To: caml-list

Dear Jean-Baptiste,
  If you have a complicated piece of code it might be better to use
Lexing.from_file instead of Lexing.from_string.

Also the evaluations made in the top-level will be cumulative:

you could do:

open "Jean";;

results := ["cats";"dogs";"fish];;

This assumes the module "jean.ml" previously compiled has a "let result = ref [];;"

By this means data can be exchanged between top-level and your own module.

If the last calculation in your parsed string/file has type unit, nothing will be printed, apart from status

I don't think there is anything type-unsafe about it, or any difference with the normal top-level really,
just you need to be aware the expressions are not checked at compile time, so you need to be
careful to check for errors.

> 
> 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] only message in thread

only message in thread, other threads:[~2012-07-11 11:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20120711100008.A0D467ED34@sympa.inria.fr>
2012-07-11 11:18 ` [Caml-list] Re: caml-list Digest Wed, 11 Jul 2012 Kimmitt, Jonathan Richard Robert (Student)

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