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 LAA29875; Thu, 8 Jan 2004 11:37:29 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA31710 for ; Thu, 8 Jan 2004 11:37:28 +0100 (MET) Received: from mailer.zkm.de (mailer.zkm.de [193.197.168.42]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i08AbR527515 for ; Thu, 8 Jan 2004 11:37:27 +0100 (MET) Received: from mail.zkm.de (localhost [127.0.0.1]) by mailer.zkm.de (8.12.9/8.12.5) with ESMTP id i08AcI8I012626 for ; Thu, 8 Jan 2004 11:38:18 +0100 (MET) Received: from zkm.de (ruth.zkm.de [192.168.200.57]) by mail.zkm.de (8.12.9/8.12.9) with ESMTP id i08AcH9j012622 for ; Thu, 8 Jan 2004 11:38:17 +0100 (MET) Message-ID: <3FFD8815.3060103@zkm.de> Date: Thu, 08 Jan 2004 11:40:53 -0500 From: Adolf Mathias User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031210 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] adding an ocaml interpreter to my C program References: <20040107005029.V39150@demos.bsdclusters.com> <20040107130048.GA18624@redhat.com> <20040107130741.U5621@demos.bsdclusters.com> In-Reply-To: <20040107130741.U5621@demos.bsdclusters.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; zkm:99 caml-list:01 kip:99 doable:01 toploop:01 toploop:01 formatter:01 beginner's:01 ocaml:01 ocaml:01 bytecode:01 toplevel:01 toplevel:01 float:02 linking:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dear list, Kip Macy wrote: >>Also, it only works for bytecode. (And it only works for compiled >>code - linking in the toplevel so you can parse ML directly is a >>different thing entirely). >> >> > > >I didn't read the message closely enough initially. Linking in the >toplevel is my stated intention. I'd like to be able to use ocaml >as an application scripting language. This is doable, but not a 2 >minute copy-paste operation as with perl. > > As Rich said, the first one seems simple, and the second one is an entirely different story. I tried to copy some of the toplevel stuff, and got the following function working: let myeval str = let lb = Lexing.from_string str in let phr = !Toploop.parse_toplevel_phrase lb in ignore(Toploop.execute_phrase true Format.std_formatter phr);; With it, I can interactively eval strings, like in #myeval "sin 45.0;;";; - : float = 0.850903524534118438 - : unit = () Hooray, it works. It becomes obvious though that the scope of O'Caml is slightly different than that of embeddable scripting languages like Lua, where lua_dostring (the equivalent of the above) is a fundamental library function, and written in C. There is one thing that puzzles me though: I can't get access to symbols like Parse.toplevel_phrase like it is done in toplevel.ml, but have to access it via !Toploop.parse_toplevel_phrase. Is this a question for the Ocaml beginner's list? Dolfi ------------------- 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