caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Francois Berenger <francois.berenger@inria.fr>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] getting the name of a function from its body
Date: Tue, 2 Jun 2015 17:21:54 +0900	[thread overview]
Message-ID: <122414E6-2549-4386-8106-2D18ECB8D787@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <556D64EC.7060800@inria.fr>

On 2015/06/02 17:10, Francois Berenger wrote:
> 
> 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.


You make a good point here.
The subtlety however is that it would require keeping track of the enclosing function name in the compiler, which is not done at all currently.
Also, this feature would require some kind of specification: I suppose by function you mean the enclosing toplevel let, but we also have the case of classes, where the occurence might be in the initialization part or inside a method, and of course cases where the definition has no name (toplevel expression of pattern-matching with several components).
Also should we do something special for submodules? functors?
Anything may be better than nothing, but this ends up being clearly more complex than __FILE__ and __LINE__, which come directly from the parser and are readily available in the syntax tree.

Jacques

  reply	other threads:[~2015-06-02  8:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 11:42 Gustave Nimant
2015-06-01 11:46 ` Fabrice Le Fessant
2015-06-01 11:52   ` Gabriel Scherer
2015-06-01 16:36   ` Gustave Nimant
2015-06-01 16:46     ` Francois Berenger
2015-06-01 17:38       ` Gustave Nimant
2015-06-01 18:07         ` Yotam Barnoy
2015-06-01 21:57     ` Fabrice Le Fessant
2015-06-02  8:10       ` Francois Berenger
2015-06-02  8:21         ` Jacques Garrigue [this message]
2015-06-02  8:37           ` Romain Bardou
2015-06-04 18:48         ` Damien Doligez
2015-06-02  8:45       ` Gerd Stolpmann
2015-06-01 14:57 ` [Caml-list] Getting the list of available function within a module Nicolas Ratier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=122414E6-2549-4386-8106-2D18ECB8D787@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=francois.berenger@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).