From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA07333; Wed, 7 Apr 2004 23:06:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 XAA07086 for ; Wed, 7 Apr 2004 23:05:59 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i37L5sYM021363; Wed, 7 Apr 2004 23:05:55 +0200 Received: from bourg.inria.fr (bourg.inria.fr [128.93.11.100]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA07146; Wed, 7 Apr 2004 23:05:54 +0200 (MET DST) Received: from starynke by bourg.inria.fr with local (Exim 4.31) id 1BBKEe-0003dT-Fc; Wed, 07 Apr 2004 23:05:24 +0200 Date: Wed, 7 Apr 2004 23:05:24 +0200 To: John Goerzen , caml-list@inria.fr Subject: Re: [Caml-list] Dynamically evaluating OCaml code Message-ID: <20040407210524.GA13909@bourg.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i From: Basile Starynkevitch X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 dynamically:01 basile:01 basile:01 2004:99 python:01 python's:01 python:01 metaocaml:01 runtime:01 metaocaml:01 leroy's:01 runtime:01 gcaml:01 terrible:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 114 On Wed, Apr 07, 2004 at 06:47:30PM +0000, John Goerzen wrote: > I am moving from Python to OCaml and one of the things I miss is > Python's eval() call. It takes a string representing a bit of Python > source code, evaluates it, and returns the result. I would like to be > able to do similar things with OCaml. As observed by others, there is a big typing issue around this (what would be the type of the eval function)? If you really need something, you could hack the toplevel (at your own risk). I don't think it is a good idea, unless you did very well understood what you really want to do. However, the functional values are usually enough to avoid the "eval", and an "eval" won't be really safe. Also, you could use metaocaml, which provide constructs (inspired by eval) to typefully meta-program, ie generate programs at runtime in a rather safe manner. See http://www.cs.rice.edu/~taha/MetaOCaml/ for more. dynamics (like old work from Leroy & Mauny - see X.Leroy's publication pages on http://cristal.inria.fr/~xleroy ) and runtime type information (like in Jun Furse GCaml) might also help - and are in some remote way a bit related to eval's typing. In addition to typing issues, there is also a runtime issue: dynamic code generation really requires garbage collection of executable code, which is not available in Ocaml (and would be terrible to implement - it would mean rewrite most of the system) ________________ However, for the beginner, the good answer (at least as given by Ocaml gurus here) to the usual "I want eval" request is simply "no you don't really need it" -- Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr Project cristal.inria.fr - INRIA Rocquencourt http://cristal.inria.fr/~starynke --- all opinions are only mine ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners