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 TAA28746; Thu, 8 Apr 2004 19:31:29 +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 TAA28685 for ; Thu, 8 Apr 2004 19:31:28 +0200 (MET DST) Received: from cs.rice.edu (cs.rice.edu [128.42.1.30]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i38HVQYM018628 for ; Thu, 8 Apr 2004 19:31:27 +0200 Received: from localhost (calypso.cs.rice.edu [128.42.1.127]) by cs.rice.edu (Postfix) with ESMTP id 23EFA4AD72; Thu, 8 Apr 2004 12:31:26 -0500 (CDT) Received: from cs.rice.edu ([128.42.1.30]) by localhost (calypso.cs.rice.edu [128.42.1.127]) (amavisd-new, port 10024) with LMTP id 22684-01-26; Thu, 8 Apr 2004 12:31:25 -0500 (CDT) Received: from boromir.cs.rice.edu (boromir.cs.rice.edu [128.42.129.71]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by cs.rice.edu (Postfix) with ESMTP id C647A4AC73; Thu, 8 Apr 2004 12:31:25 -0500 (CDT) Date: Thu, 8 Apr 2004 12:31:25 -0500 (CDT) From: Walid Taha To: John Goerzen Cc: caml-list@inria.fr Subject: Re: [Caml-list] Dynamically evaluating OCaml code In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavis-20030616-p7 at cs.rice.edu 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 metaocaml:01 val:01 val:01 python:01 python's:01 python:01 usr:01 bug:01 faq:01 faq:01 beginner's:01 beginners:01 bin:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 167 Hi John, You might want to take a look at MetaOCaml. Instead of strings it uses "Brackets" (written .<...>.) and uses ".!" for "eval". Here's a simple interactive session: # let a = .< 1 + 2 >.;; val a : int code = .<(1 + 2)>. # let b = .< .~a + .~ a >.;; val b : int code = .<((1 + 2) + (1 + 2))>. # let c = .! a;; val c : int = 3 # let d = .! b;; val d : int = 6 Notice that the also type checks what goes inside the brackets (it doesn't just say "code", it says "int code"). Walid. On Wed, 7 Apr 2004, John Goerzen wrote: |Hello, | |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. | |I have observed that /usr/bin/ocaml, the interactive top-level, is |itself written in OCaml, which suggests that this should be possible. |Although I have tried to study the source for this, it seems extremely |complex and I can't figure out a way to do the simple evaluation |described above. | |Can anyone help me out here? | |Thanks, |John | | |------------------- |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 | -- ------------------- 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