Previous Contents Next
Chapter 2 Quotations
This chapter presents the Camlp4 quotation system. A quotation is a part of a program enclosed by special parentheses in position of expression or pattern (exclusively), and whose treatment is done by an user function, called a ``quotation expander''. Several quotations are usable in the same source code.

When Camlp4 encounters such a construction, the appropriate quotation expander is called with the string contents of the quotation.

There are two kinds of quotation expanders:
2.1 Syntax

There are two kinds of quotations: The string inside a quotation is any string. It can hold other quotations. The string sequences ``<<'', ``<:id<'' and ``>>'', if not matching, must be prefixed by a backslash and backslashes must be doubled.

2.2 Creating a quotation expander

A quotation expander is a function written in OCaml. A call to the Camlp4 library function ``Quotation.add'' (see section 7.7) adds the quotation expander. The variable ``Quotation.default'' holds the name of the default quotation.

The file holding the quotation expander must be compiled using the OCaml compiler, with the Camlp4 library directory in its directory path (option ``-I''). An object file (ending with ``.cmo'') is created, which is loadable in Camlp4, as parameter of the command ``camlp4'', or in the OCaml toplevel using the directive ``#load''.

2.3