caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Kimmitt, Jonathan Richard Robert (Student)" <jonathan.kimmitt@student.anglia.ac.uk>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] Re: caml-list Digest Wed, 11 Jul 2012
Date: Wed, 11 Jul 2012 11:18:34 +0000	[thread overview]
Message-ID: <4EC2D5DC-6E1B-427A-8213-6E55CB32306B@student.anglia.ac.uk> (raw)
In-Reply-To: <20120711100008.A0D467ED34@sympa.inria.fr>

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



           reply	other threads:[~2012-07-11 11:18 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20120711100008.A0D467ED34@sympa.inria.fr>]

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=4EC2D5DC-6E1B-427A-8213-6E55CB32306B@student.anglia.ac.uk \
    --to=jonathan.kimmitt@student.anglia.ac.uk \
    --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).