From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 01AFC7F3B1 for ; Tue, 3 Mar 2020 12:35:34 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.70,511,1574118000"; d="scan'208";a="341085766" Received: from org51-h01-176-134-229-12.dsl.sta.abo.bbox.fr (HELO pl347-pro) ([176.134.229.12]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES256-GCM-SHA384; 03 Mar 2020 12:35:34 +0100 User-agent: mu4e 1.1.0; emacs 26.3 From: Thierry Martinez To: caml users Date: Tue, 03 Mar 2020 12:35:33 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Subject: [Caml-list] [ANN] First release of metapp 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.