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 WAA04897; Wed, 7 Apr 2004 22:37:43 +0200 (MET DST) 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 WAA04258 for ; Wed, 7 Apr 2004 22:37:42 +0200 (MET DST) Received: from babasse.residence.ens-lyon.fr (babasse.residence.ens-lyon.fr [140.77.128.152]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i37KcZjq022970 for ; Wed, 7 Apr 2004 22:38:35 +0200 Received: from localhost ([127.0.0.1] helo=babasse) by babasse.residence.ens-lyon.fr with smtp (Exim 4.31) id 1BBJnj-0004ag-9T for caml-list@inria.fr; Wed, 07 Apr 2004 22:37:35 +0200 Date: Wed, 7 Apr 2004 22:37:32 +0200 From: Samuel Mimram To: caml-list@inria.fr Subject: Re: [Caml-list] Dynamically evaluating OCaml code Message-Id: <20040407223732.58ed9218@babasse> In-Reply-To: References: X-Mailer: Sylpheed version 0.9.10claws (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="Signature=_Wed__7_Apr_2004_22_37_32_+0200_1FM_==kWId92r9fU" X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; samuel:01 samuel:01 ens-lyon:01 caml-list:01 dynamically:01 2004:99 python:01 python's:01 python:01 usr:01 segfaults:01 toto:01 dynamically:01 dynlink:01 ens-lyon:01 X-Attachments: type="application/pgp-signature" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 111 --Signature=_Wed__7_Apr_2004_22_37_32_+0200_1FM_==kWId92r9fU Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Le Wed, 7 Apr 2004 18:47:30 +0000 (UTC) John Goerzen a =E9crit : > Hello, >=20 > 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. >=20 > 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. >=20 > Can anyone help me out here? >=20 > Thanks, > John Such a function cannot be programmed in OCaml because it would break the typing system: what would the type of "eval"? 'a? The following code could then lead to segfaults: let n =3D ref "toto" in n :=3D eval "9" because the typing system is borken: n is a string ref and gets an integer! And there's no way to avoid that. The only thing you can do is to dynamically load compiled bytecode files (cf. the Dynlink module). Samuel. --=20 Samuel Mimram samuel.mimram@ens-lyon.fr --Signature=_Wed__7_Apr_2004_22_37_32_+0200_1FM_==kWId92r9fU Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAdGaMIae1O4AJae8RAvxMAJ9ViknqdF8++iPwWpHA3GRZoUJFWQCfeUEo iF/7l8qA9SUrWzMKZqr970Q= =6O9i -----END PGP SIGNATURE----- --Signature=_Wed__7_Apr_2004_22_37_32_+0200_1FM_==kWId92r9fU-- ------------------- 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