From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA02389 for caml-red; Wed, 22 Nov 2000 09:31:28 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA16741 for ; Tue, 21 Nov 2000 20:11:19 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eALJBI514770 for ; Tue, 21 Nov 2000 20:11:18 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id eALJBIH73259 ; Tue, 21 Nov 2000 20:11:18 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id UAA07524 ; Tue, 21 Nov 2000 20:11:18 +0100 (MET) Date: Tue, 21 Nov 2000 20:11:18 +0100 (MET) From: Alain Frisch To: John Matthews cc: caml-list@inria.fr Subject: Re: First-class evaluation In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr 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