From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5BCA07EE7D for ; Tue, 2 Jun 2015 10:10:22 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.13,538,1427752800"; d="scan'208";a="132990680" Received: from meleze.ens.fr (HELO [129.199.99.114]) ([129.199.99.114]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 02 Jun 2015 10:10:20 +0200 Message-ID: <556D64EC.7060800@inria.fr> Date: Tue, 02 Jun 2015 10:10:20 +0200 From: Francois Berenger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <556C4512.2050002@free.fr> <556C89F3.3000206@free.fr> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] getting the name of a function from its body On 06/01/2015 11:57 PM, Fabrice Le Fessant wrote: > The main reason for the absence of __FUNCTION__ is probably that it > does not really make sense : you might have several functions with the > same name within the same module : > > let f x = x+1 > let f list = List.map f list > > It makes sense in C, because you can only define a symbol once in a > file, so the pair (__FILE__, __FUNCTION__) is uniq (and if the > function is not static, it is probably even uniq within the > executable). > > In OCaml, it is probably better to use the pair (__FILE__, __LINE__) > to tell the dev where to search for the problem. Then, the triplet (__FILE__, __LINE__, __FUNCTION__) is unique in OCaml. The problem I saw a long time ago while working with people who were not programmers (but still scientits) is that they have more chance to fix an error in one of their input file when given the function name than when not. And since I created and maintain a logging library in OCaml, I was (and I am still) interested into making log messages as useful as possible to end users. > --Fabrice > > > > > > On Mon, Jun 1, 2015 at 6:36 PM, Gustave Nimant wrote: >> On 01/06/2015 13:46, Fabrice Le Fessant wrote: >>> >>> Recent versions of OCaml provide "__LOC__", "__FILE__", "__LINE__", >>> "__MODULE__" and "__POS__" primitives that can be used to display >>> precise error messages. >>> >>> --Fabrice >> >> Thank you for this information I was not aware of. >> It seems that the functions described in >> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html >> do not answer my question : >> "how to get the name of the current function ?" >> >> Do I miss something ? >> >> >> Gustave >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > > > -- Regards, Francois.