2

I am using camlp5 with the MLast module. I would like to know the syntax for antiquotations of nesting depth greater than 1. I'll explain with a mock example. Suppose I have

let f1 e = <:expr< 3 * $e$ >>
let f2 e = <:expr< $e$ + 1 >>
let f3 e = <:expr< $e$ / 2 >>
let f123 e = f3 (f2 (f1 e))

How can I define f123 in one go? For only two parts I could do

let f12 e = <:expr< $<:expr< 3 * \$e\$ >>$ + 1 >>

Note the mandatory backslashes in the inner antiquotation. But for three parts? Neither of the following works:

let f123 e = <:expr< $<:expr< \$<:expr< 3* \$e\$ >>\$ + 1 >>$ / 2 >>
let f123 e = <:expr< $<:expr< \$<:expr< 3* \\$e\\$ >>\$ + 1 >>$ / 2 >>
let f123 e = <:expr< $<:expr< \$<:expr< 3* \\\$e\\\$ >>\$ + 1 >>$ / 2 >>

The respective error messages are:

Uncaught exception: Pcaml.Qerror ("expr", 1, _)
Uncaught exception: Pcaml.Qerror ("expr", 1, _)
Parse error: end of input expected after [expr] (in [expr_eoi])

I couldn't find anything in the docs.

(P.S. Of course I know that in this specific example I could omit the inner antiquotation/quotation pairs. That is beside the point; it is due to the oversimplification inherent in the mock example.)

kne
  • 1,398
  • 7
  • 12
  • Is it ocamlp4 (tag) or ocamlp5 (title)? – coredump Feb 18 '17 at 13:17
  • @coredump: It is camlp5. There is no tag for camlp5 yet and camlp5 is a fork of camlp4: AFAIUI, at some point the maintainers of camlp4 decided to do a complete (and not backwards-compatible) overhaul and camlp5 is a continuation of the original project. Hence I assumed that camp4 is OK as a tag. – kne Feb 18 '17 at 18:25

0 Answers0