English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Dynamically evaluating OCaml code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-08 (07:50)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Dynamically evaluating OCaml code
On Thu, 2004-04-08 at 06:39, John Goerzen wrote:
> On Thu, Apr 08, 2004 at 01:32:41AM +0400, Vitaly Lugovsky wrote:

> I don't think that will help me here; I'm looking at being able to let
> people insert OCaml expressions directly into otherwise plain-text
> config files.

Yeah, you can do that! But you need to be tricky!

Analyse the file, changing the plain text parts to
strings. You may need some wrappers like:

option5 = /dev/null


print_endline "option5 = /dev/null"

Now you can compile the file with Ocaml, and execute it.

This is very nice because you WILL be typechecking the code
fragments. Indeed you can do better, by making the client
write the WHOLE file in psuedo code that translates
to Ocaml, then the code executes things, instead of just
printing a text file to be run through bash, or some other
text interpreter.

By the way the code fragment technique is exactly what
my interscript literate programming tool does,
which makes it vastly superior to similar tool:
it embeds Python though, which does have 'eval'.

You might want to use it instead..since it already
does what you want .. and happens to be able to 
pretty print HTML documentation as well :D

John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net

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