caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 compilation model
@ 2009-01-24 20:15 Mikkel Fahnøe Jørgensen
  2009-01-24 20:34 ` [Caml-list] " blue storm
  2009-01-25  9:49 ` Richard Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Mikkel Fahnøe Jørgensen @ 2009-01-24 20:15 UTC (permalink / raw)
  To: O'Caml Mailing List

Hi,

I've put camlp4 on the backburner, but I think it is useful to know it
a bit better, especially because several libraries are using it.

a) I understand you can write a cryptic ocaml program that effectively
builds and AST from whatever grammar you decide by applying camlp4.
b) I also understand that camlp4 it has a built in ocaml syntax that
you can extend, and therefore use as camlp4 as a prepreprocessor to
the ocaml compiler as part of the build process.

In a) it makes sense that a library can embed (link with) camlp4 logic
to parse strings without the enduser needing to refer to camlp4 in the
build process.

In b) you would normally require the user to apply the preprocessor to
the source code as part of the build process.

But know my question:

It seems that an enduser program can link with a camlp4 enhanced
library and magically have its syntax extended without adding camlp4
to the build process (once the library has been built). For example
the bitstring library introduces the bitmatch syntax.

Is this correct understood, and how does that work?

One reason I put camlp4 on hold was precisely that added compilation
complexity, but if it can be hidden in a library, it is an entirely
different situation.


Regards,
Mikkel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] camlp4 compilation model
  2009-01-24 20:15 camlp4 compilation model Mikkel Fahnøe Jørgensen
@ 2009-01-24 20:34 ` blue storm
  2009-01-25  9:49 ` Richard Jones
  1 sibling, 0 replies; 4+ messages in thread
From: blue storm @ 2009-01-24 20:34 UTC (permalink / raw)
  To: Mikkel Fahnøe Jørgensen; +Cc: O'Caml Mailing List

On 1/24/09, Mikkel Fahnøe Jørgensen <mikkel@dvide.com> wrote:
> a) I understand you can write a cryptic ocaml program that effectively
> builds and AST from whatever grammar you decide by applying camlp4.

Right.

> b) I also understand that camlp4 it has a built in ocaml syntax that
> you can extend, and therefore use as camlp4 as a prepreprocessor to
> the ocaml compiler as part of the build process.

Right. It is actually a bit more modular than that : Camlp4 has
built-in Ocaml AST and quotations (~ syntaxic sugar for AST
constructors in expressions or patterns), and provide a way to extend
any camlp4-defined syntax. OCaml compilers can integrate preprocessors
(not only camlp4, see eg.
http://people.csail.mit.edu/mikelin/ocaml+twt/ ) as a part of the
build process.

> It seems that an enduser program can link with a camlp4 enhanced
> library and magically have its syntax extended without adding camlp4
> to the build process (once the library has been built). For example
> the bitstring library introduces the bitmatch syntax.
>
> Is this correct understood, and how does that work?

I do not think it is correct. IIRC, bitstring needs (when using the
syntaxic extension) camlp4 in the user build process. Richard Jones
may correct me on this though.

> One reason I put camlp4 on hold was precisely that added compilation
> complexity, but if it can be hidden in a library, it is an entirely
> different situation.

I do not know of any way of "hiding" the preprocessing phase.
That said, the build process does not have to be painful. You can use
ocamlfind ( http://projects.camlcity.org/projects/dl/findlib-1.2.1/doc/guide-html/x412.html
), or ocamlbuild, to integrate syntax extensions more easily.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] camlp4 compilation model
  2009-01-24 20:15 camlp4 compilation model Mikkel Fahnøe Jørgensen
  2009-01-24 20:34 ` [Caml-list] " blue storm
@ 2009-01-25  9:49 ` Richard Jones
  2009-01-25  9:55   ` Mikkel Fahnøe Jørgensen
  1 sibling, 1 reply; 4+ messages in thread
From: Richard Jones @ 2009-01-25  9:49 UTC (permalink / raw)
  To: Mikkel Fahnøe Jørgensen; +Cc: caml-list

On Sat, Jan 24, 2009 at 09:15:43PM +0100, Mikkel Fahnøe Jørgensen wrote:
> It seems that an enduser program can link with a camlp4 enhanced
> library and magically have its syntax extended without adding camlp4
> to the build process (once the library has been built). For example
> the bitstring library introduces the bitmatch syntax.

No, this isn't so, at least not in bitstring.

You can link your program with bitstring.cma and get access to
the Bitstring.* library functions like the ones here:

http://et.redhat.com/~rjones/bitstring/html/Bitstring.html#reference

but you cannot use the special bitmatch syntax without preprocessing
your source code with camlp4.

It's trivial to add the preprocessor if you use ocamlfind, so in
practice this is not a problem.

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] camlp4 compilation model
  2009-01-25  9:49 ` Richard Jones
@ 2009-01-25  9:55   ` Mikkel Fahnøe Jørgensen
  0 siblings, 0 replies; 4+ messages in thread
From: Mikkel Fahnøe Jørgensen @ 2009-01-25  9:55 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

2009/1/25 Richard Jones <rich@annexia.org>:
> On Sat, Jan 24, 2009 at 09:15:43PM +0100, Mikkel Fahnøe Jørgensen wrote:
>> It seems that an enduser program can link with a camlp4 enhanced
>> library and magically have its syntax extended without adding camlp4
>> to the build process (once the library has been built). For example
>> the bitstring library introduces the bitmatch syntax.
>
> No, this isn't so, at least not in bitstring.
>

OK, thank you both for clarifying this.

Mikkel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-01-25  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-24 20:15 camlp4 compilation model Mikkel Fahnøe Jørgensen
2009-01-24 20:34 ` [Caml-list] " blue storm
2009-01-25  9:49 ` Richard Jones
2009-01-25  9:55   ` Mikkel Fahnøe Jørgensen

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).