Version française
Home     About     Download     Resources     Contact us    
Browse thread
weird behavior with camlp4o
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] weird behavior with camlp4o
It's  more  about  locations  that  efficiency,  if camlp4o was printing OCaml
source code, then the locations will be those of the translated code.

Camlp4  used  to always print by default the binary output. I found this quite
annoying  when  developing Camlp4 extensions because I always forget to give a
proper pretty printer and the binary output just screwed up my terminal.

So Camlp4 now automatically use the pretty-printer when stdout is a tty [1].

However this does not prevent you from reading the little docs about camlp4 :)

Cheers,

[1]: http://brion.inria.fr/gallium/index.php/Using_Camlp4

Excerpts from Olivier Andrieu's message of Wed Apr 09 09:36:40 +0200 2008:
> On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> > Selon "Andrew I. Schein" <andrew@andrewschein.com>:
> >  > Greetings list -
> >  >
> >  > I was playing around with OCaml 3.10.2 camlp4o like this:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml
> >  >
> >  > with my macro pa_breakcont.cmo and got the expected macro translation
> >  > printed to my terminal.  However, when I type:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
> >  >
> >  > out.ml contains binary output.  Am I misusing camlp4o?
> >
> >  I have encountered the same problem a few days ago while working on
> >  Ocaml-Java to make it camlp4-compatible.
> >
> >  The fact is that the kind of output (binary dump of abstract tree or
> >  source code in textual form) is chosen according to the nature of the
> >  output file descriptor. If the output file descriptor denotes a tty
> >  then the textual form is chosen, otherwise the binary form is chosen.
> >
> >  That being said, I don't know what is the rationale of this choice,
> >  as I have not come up with a use case for the binary form.
> 
> It's simply more efficient for ocamlc or ocamlopt when camlp4 is
> called via the -pp option: no need to pretty-print and then reparse
> the source.
> 

-- 
Nicolas Pouillard aka Ertai