caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Thomas Refis <thomas.refis@gmail.com>
To: Philippe Veber <philippe.veber@gmail.com>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Accessing values calculated by Toploop.execute_phrase
Date: Thu, 11 Feb 2016 14:28:43 +0000	[thread overview]
Message-ID: <CAJ_epFO+mGHhLKpHqU1rVtYfadD=FzPNxe-3xJesUDEpmx5b8Q@mail.gmail.com> (raw)
In-Reply-To: <CAOOOohQNWy_24PaJStapsPrfwgZxrriM4cLuQr8_y3ROY5_7=g@mail.gmail.com>

2016-02-11 14:11 GMT+00:00 Philippe Veber <philippe.veber@gmail.com>:
>   I'm having quite some fun interacting with the toplevel using `Toploop`
> and co., and I am now looking for a way to get the values created during a
> call to `Toploop.execute_phrase`, which sadly only returns a boolean. I
> would like to get these values as `Obj.t` values, so that I could perform
> additional computations for certain types.
>
> I'm almost there but not yet:
>   - I can find which values were created and what's their type by collecting
> `Outcometree.out_path` values when they are printed, but this doesn't give
> access to the actual value (represented as an `Obj.t`).
>   - I could use `Toploop.getvalue`, but then I could not get results of
> evaluations that were not bound to a variable.

Well, you can hack around the final problem by rewriting the
expression you feed to [execute_phrase] so the result is always bound
to a variable.
[Toploop.execute_phrase] already has a bit of code to check whether
the result is a value not bound to any name (
https://github.com/ocaml/ocaml/blob/trunk/toplevel/toploop.ml#L263 ),
you could do something similar on your side. This works on the
typedtree but you can do the same on the parsetree. Or you could type
your expression beforehand, reuse that exact piece of code, but only
when the value is of the type you want (since you apparently want to
do extra computations "for certain types").

Thomas.

PS: https://www.youtube.com/watch?v=p8oi6M4z_e0

  reply	other threads:[~2016-02-11 14:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 14:11 Philippe Veber
2016-02-11 14:28 ` Thomas Refis [this message]
2016-02-11 15:37   ` Philippe Veber
2016-02-11 15:42     ` Thomas Refis

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='CAJ_epFO+mGHhLKpHqU1rVtYfadD=FzPNxe-3xJesUDEpmx5b8Q@mail.gmail.com' \
    --to=thomas.refis@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=philippe.veber@gmail.com \
    /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).