I am testing out quotations in Camlp4. My tester.ml program is as follows:
open Camlp4.PreCast;;
let x = <:Cstm< x = 1 + 2 >>;;
let y = <:expr< let y = 1 + 2 >>;;
print_string "done";;
I have tried compiling this in various ways, eg.
ocamlc -pp "camlp4of pa_extend.cmo -loc" -I +camlp4 tester.ml
however the executable produced doesn't print out "done" as expected. How should I compile this file?
camlp4 --helpsays:You forget the argument for
-loc. You can check the consequence of this byocamlc's-verboseoption. (-verboseis really handy to find out what are exactly happening in the compilation):The input file name
tester.mlis not treated as a file name but is considered as the name of location variables. With the empty inputcamlp4ofoutputs an empty program and it is compiled byocamlc. That's why the final executable does nothing.You code contains a strange quotation name
Cstrm, andlet y = 1 + 2is not an expression but a structure item. The following is one of the nearest codes which compile:You can check the output of CamlP4 in a human readable form with
-printer Camlp4OCamlPrinteroption. This is another important technique to work with CamlP4: