Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <frisch@clipper.ens.fr>
To: John Matthews <johnm@crl.dec.com>
Cc: caml-list@inria.fr
Subject: Re: First-class evaluation
Date: Tue, 21 Nov 2000 20:11:18 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.04.10011212003080.2953-100000@clipper.ens.fr> (raw)
In-Reply-To: <C88F387E7F6ED4118B5308002BC3EB1E07AC4C@yen.crl.dec.com>

On Tue, 21 Nov 2000, John Matthews wrote:

> Does the Ocaml interpreter provide a mechanism for interactively evaluating
> strings or abstract syntax tree representations of Ocaml code? I'm looking
> for something along the lines of Common Lisp's "eval" mechanism. If so, does
> it work in the presence of the source-level debugger? That is, can I step
> into a call to "eval"?

The undocumented toplevellib.cma library provides some entry points to the
toplevel evaluator. To communicate with the main program, the "script"
may access the modules loaded before the call to the evaluator.

For instance:

File top_test.ml:
====
open Toploop;;

let exec s = 
  let ast = !parse_toplevel_phrase (Lexing.from_string s) in
  ignore (execute_phrase false Format.std_formatter ast);;

exec "open Pervasives;;";;
exec "Share.result := 10 + 2*3;;";;

Printf.printf "Result = %i\n" !Share.result;;
====

File share.ml:
====
let result = ref 0;;
====


You compile and link with:
ocamlc -o top_test toplevellib.cma share.ml top_test.ml


The source and interfaces for the library is in the toplevel/ subdirectory
of the ocaml distribution.


I think you can't use the debugger the way you would like: if you trace
the call to execute_phrase, you debug the evaluator, not the code you
evaluate.

Hope this helps.


-- 
  Alain Frisch



      reply	other threads:[~2000-11-22  8:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-21 14:28 John Matthews
2000-11-21 19:11 ` Alain Frisch [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=Pine.GSO.4.04.10011212003080.2953-100000@clipper.ens.fr \
    --to=frisch@clipper.ens.fr \
    --cc=caml-list@inria.fr \
    --cc=johnm@crl.dec.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