From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p737BBCI018230 for ; Wed, 3 Aug 2011 09:11:11 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqUFAPzzOE7RVdQzk2dsb2JhbABCmBSPPwgUAQEBAQkJCwkUBCGBQAEBAQEDEgIsARsSCwEDDAYFCw0NISIBEQEFAQoSBhMIChCHTqJzCowvglSEZzuIbQIDBoY8BJJ7jEw8g14 X-IronPort-AV: E=Sophos;i="4.67,309,1309730400"; d="scan'208";a="104567153" Received: from mail-vw0-f51.google.com ([209.85.212.51]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Aug 2011 09:11:05 +0200 Received: by vws20 with SMTP id 20so337697vws.10 for ; Wed, 03 Aug 2011 00:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=P2OquStCR9kcxKVs/fnPsDHCpXZssrBxKc7NPJ8BQ18=; b=Wsq6bkHbGZaEDJ2OSqAgCKifG7XRKFvsYlMsYQLgZ0t6zIKsCvNs84DxqbF9v+6pIf flx64PQxw3FPvgHvwowYWxLqxakUCdOIosvZxwKrAewqQPU+RZhq8zUbYUYcKB4pmZ5f lYmLESTH3yzceiWWA/8h19gtcPBMBoIEw0+qU= Received: by 10.52.110.68 with SMTP id hy4mr4445971vdb.97.1312355464097; Wed, 03 Aug 2011 00:11:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.159.10 with HTTP; Wed, 3 Aug 2011 00:10:44 -0700 (PDT) In-Reply-To: <4E38E4F8.6020300@fugmann.net> References: <4E37EBA3.6040800@fugmann.net> <4E386A65.8080000@ens-lyon.org> <4E38E4F8.6020300@fugmann.net> From: Gabriel Scherer Date: Wed, 3 Aug 2011 09:10:44 +0200 Message-ID: To: Anders Fugmann Cc: Martin Jambon , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p737BBCI018230 Subject: Re: [Caml-list] filename and line number. 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 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 > >