caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Thierry Martinez <Thierry.Martinez@inria.fr>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] [ANN] First release of metapp
Date: Tue, 03 Mar 2020 12:35:33 +0100	[thread overview]
Message-ID: <ow4k1411xiy.fsf@pl347-pro.paris.inria.fr> (raw)

Dear users of OCaml,

I am happy to announce the first release of metapp, yet another
preprocessor for OCaml. Similarly to ppx_optcomp, metapp is a PPX
rewriter. But instead of introducing a specific DSL for preprocessor
directives, metapp provides a [%meta ...] extension, where the dots
... are arbitrary OCaml expressions that are substituted at compile-time
by the AST nodes they evaluate into. These expressions build AST nodes
either by (anti-)quoting some code directly, or by using compiler-libs
(Parsetree, Ast_helper, ...).

In particular, this preprocessor is easy to use for conditional
compilation, and is an alternative to cppo and ppx_optcomp.

let option_get o =
  [%meta if Sys.ocaml_version >= "4.08.0" then
     [%e Option.get o]
  else
     [%e match o with
     | None -> invalid_arg "option_get"
     | Some x -> x]]

In this example, the code between [%e ... ] is "anti-quoted": it is the
code that is inserted (conditionally) in the rewritten module. Of
course, the anti-quoted code can contain itself some [%meta ...]
code. [%meta ...] can even itself contain other levels of [%meta ...]
code for multi-stage programming.

An example of usage of metapp is the metaquot package, which implements
the same quoters as ppx_tools.metaquot: [%expr ...], [%type: ...],
etc. These quoters are implemented by meta-programming: the meta-code
introspects Parsetree.cmi from compiler-libs to generate the code
matching the current OCaml version.

Happy hacking,
-- 
Thierry.

             reply	other threads:[~2020-03-03 11:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 11:35 Thierry Martinez [this message]
2020-03-03 13:20 ` Thierry Martinez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ow4k1411xiy.fsf@pl347-pro.paris.inria.fr \
    --to=thierry.martinez@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).