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
Name of currently executing function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-20 (16:17)
From: Dave Benjamin <dave@r...>
Subject: Re: [Caml-list] Name of currently executing function
Thanks again for your help, blue storm. I condensed this technique into 
a simple example for PLEAC, which I just committed here:


It allows you to write this:

(* An example named function. *)
let test_function () =
   let str = "Hello, world!" in
   let num = 42 in
   LOG "str=\"%s\", num=%d" str num;
   print_endline "test complete"

(* Some code to run at the toplevel. *)
let () =
   LOG "not in a function";
   test_function ()

And get the following output:

<toplevel>[main.ml]: not in a function
test_function[main.ml]: str="Hello, world!", num=42
test complete