caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Anders Fugmann <anders@fugmann.net>
Cc: Martin Jambon <martin.jambon@ens-lyon.org>, caml-list@inria.fr
Subject: Re: [Caml-list] filename and line number.
Date: Wed, 3 Aug 2011 09:10:44 +0200	[thread overview]
Message-ID: <CAPFanBEEZfqVxyF+LAmULpV2hFiWyyBU54q0ZYHq_fjvcgCH4Q@mail.gmail.com> (raw)
In-Reply-To: <4E38E4F8.6020300@fugmann.net>

Both pa_macros and cppo have a file-inclusion directive, so you could
define your preferred location-reporting macro in a header file.
That said, I would personally use the __LOCATION__ macro directly: the
less preprocessing stuff the better, and if it "clutters your code"
you could restrict your reporting a bit, which may not be a bad thing:
having a log full of useless stuff is only a bit better than having no
log.

You may also be interested in the existing logging frameworks for
OCaml, such as Bolt:
  http://bolt.x9c.fr/

On Wed, Aug 3, 2011 at 8:04 AM, Anders Fugmann <anders@fugmann.net> wrote:
> Thanks for the replies,
>
> Using cppo, would I need to define 'loc' in each file using log, or can it
> be defined in another module?
>
> If not, I guess the alternative is to create a syntax extenstion that will
> include Loc.t structure as a parameter to some print function - or add it
> manually, but I would like to avoid cluttering the code with __LOCATION__
> everywhere.
>
> Regards
> Anders Fugmann
>
>
>
> On 08/02/2011 11:21 PM, Martin Jambon wrote:
>>
>> On 08/02/11 05:45, Gabriel Scherer wrote:
>>>
>>> Finally, Martin Jambon also has its own "cppo" tools mimicking cpp,
>>> which I suppose doesn't rely on camlp4, and has __FILE__ and __LINE__
>>> macros which may be in a more directly exploitable format. I have
>>> never tried it though. See:
>>>   http://martin.jambon.free.fr/cppo.html
>>
>> That's correct. Thanks for the plug.
>>
>> Here is an example:
>>
>> $ cat loc.ml
>> #define loc (Printf.sprintf "File %S, line %i" __FILE__ __LINE__)
>>
>> print_endline loc;;
>> print_endline loc;;
>>
>> $ ocamlopt -o loc -pp cppo loc.ml; ./loc
>> File "loc.ml", line 3
>> File "loc.ml", line 4
>>
>>
>>
>> Martin
>>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>


  reply	other threads:[~2011-08-03  7:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-02 12:20 Anders Fugmann
2011-08-02 12:45 ` Gabriel Scherer
2011-08-02 21:21   ` Martin Jambon
2011-08-03  6:04     ` Anders Fugmann
2011-08-03  7:10       ` Gabriel Scherer [this message]
2011-08-04  7:58         ` Anders Fugmann
2011-08-04 13:03           ` forum
2011-08-08 19:08             ` Anders Peter Fugmann
2011-08-09 16:31               ` forum
2011-08-03 19:57   ` Till Varoquaux
2011-08-03 20:52     ` Gabriel Scherer

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=CAPFanBEEZfqVxyF+LAmULpV2hFiWyyBU54q0ZYHq_fjvcgCH4Q@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=anders@fugmann.net \
    --cc=caml-list@inria.fr \
    --cc=martin.jambon@ens-lyon.org \
    /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).