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
invoke function from its name as string
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-03-13 (07:10)
From: Ludovic Coquelle <lcoquelle@g...>
Subject: Re: [Caml-list] invoke function from its name as string
On Thu, Mar 13, 2008 at 2:49 PM, Andrej Bauer
<Andrej.Bauer@fmf.uni-lj.si> wrote:
> Ludovic Coquelle wrote:
>  > (re-send as it seems it didn't go through)
>  It did.

Sorry for the double post (gmail probably filtered the mail I sent to list).

>  > First, hello everyone as it is my first message to this list ;)
>  >
>  >  I'm trying to solve this problem:
>  >  I have a module name and function name in string variables,
>  >  and I would like to call this function, like :
>  >  let mod = "MyMod" in
>  >  let fn = "my_fun" in
>  >  what_come_here mod fn
>  >
>  >  Can this problem be solved?
>  If you are new to ocaml then we can help you much better if you explain
>  what problem you are trying to solve. It looks like you are trying to
>  write in Ocaml something that is common in Python/perl/shell. There is
>  likely to be a different, better way of doing the same thing in Ocaml.
>  Best regards,
>  Andrej

Thanks for this answer.
Problem I'm trying to solve is the following:

I use 'make_suite' which is a program that do regex matching on source
code to extract a list of function that looks like OUnit tests; from
this list, it write an ocaml source code file which is a test case
that call all the previous functions found.
(see: http://skydeck.com/blog/programming/unit-test-in-ocaml-with-ounit/)

Now, instead of having a program which write a source file that I have
to compile and run, I would prefer if I can change 'make_suite' to
create the test case and run it directly.

Thus, I have a list of function's names as string and I would like a
list of functions.
Is this possible?
Is there a better way to achieve automatic test case construction?

PS: this is not a *real problem* to use an intermediate file; just
wanna learn if we can do without :)