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
scripting the toplevel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-30 (15:27)
From: Yitzhak Mandelbaum <yitzhak@r...>
Subject: scripting the toplevel

I'm interested in writing scripts that can execute code in the ocaml  
toplevel as if the user had added the input by hand. In particular,  
I'd like to let the user pass parameters to my script and then use  
those. For example,

let user_module = Sys.argv.(1);;
#load user_module;;

Or, more ambitiously,

let user_expr = Sys.argv.(1);;

The first example doesn't work, as #load needs a string literal and  
the second example works, but does not produce the desired effect -  
that of interpreting and executing an ocaml expression passed on the  
command line.  Currently, to get around these limitations I'm  
collecting the user's parameters, using them to fill in a script  
template, dumping the filled-in template into a temp file, and then  
executing "ocaml" on the temp file. I'd prefer to avoid this level of  

Yitzhak Mandelbaum

Yitzhak Mandelbaum
AT&T Labs - Research