[wg-camlp4] My uses of syntax extension

Gerd Stolpmann info at gerd-stolpmann.de
Mon Jan 28 21:55:47 GMT 2013


Am 28.01.2013 13:04:28 schrieb(en) Alain Frisch:
> camlp4.macro:  does this refer to pa_macro?  It seems that this is  
> more about conditional compilation than proper macro expansion.  I  
> suspect that conditional compilation is used rarely enough in OCaml  
> project, so that a slightly more verbose syntax would not a big  
> deal.  Do you confirm?
> 
> See  
> http://www.lexifi.com/blog/syntax-extensions-without-camlp4-lets-do-it  
> for a -ppx based version of conditional compilation.  The syntax is:
> 
>   include IFDEF(SYMBOL)(struct
>      ... (* structure items in case SYMBOL is defined *)
>   end)(struct
>      ... (* structure items in case SYMBOL is not defined *)
>   end)

Conditional compilation is not always on the level of structures.

Here is a recent code snippet from me:

   let func =
     IFDEF SAFE THEN
       ctx.functions_7.(func_idx)
     ELSE
       Array.unsafe_get ctx.functions_7 func_idx
     ENDIF in

i.e. just a fine-grained version of -unsafe. Of course, I can use  
(local) structures here as well, but the whole point is to speed the  
code up once you are sure the code is SAFE.

Macros - in the general sense - would be better handled on the level of  
tokens. That said, we could also do this by a normal -pp preprocessor  
(these are run _before_ -ppx, right?).

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd at gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


More information about the wg-camlp4 mailing list