From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 83A597EE6B for ; Mon, 25 Nov 2013 17:28:00 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.50 as permitted sender) identity=mailfrom; client-ip=209.85.214.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-bk0-f50.google.com) identity=helo; client-ip=209.85.214.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f50.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvYCAO95k1LRVdYylGdsb2JhbABZgz9TqTqSHk6BIggWDgEBAQEHCwsJEiqCJQEBBQw0ARsSCwEDDAYFCw0NISEBAREBBQEKEgYTEgeHVQEDDw2hDYxZgwmELwoZJwMKZIc2AQUMjGwkgQM1MweEMwOWKYFrgTCLKoNMGCmDFYE/Ow X-IPAS-Result: AvYCAO95k1LRVdYylGdsb2JhbABZgz9TqTqSHk6BIggWDgEBAQEHCwsJEiqCJQEBBQw0ARsSCwEDDAYFCw0NISEBAREBBQEKEgYTEgeHVQEDDw2hDYxZgwmELwoZJwMKZIc2AQUMjGwkgQM1MweEMwOWKYFrgTCLKoNMGCmDFYE/Ow X-IronPort-AV: E=Sophos;i="4.93,768,1378850400"; d="scan'208";a="37822319" Received: from mail-bk0-f50.google.com ([209.85.214.50]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 25 Nov 2013 17:27:59 +0100 Received: by mail-bk0-f50.google.com with SMTP id e11so2041487bkh.23 for ; Mon, 25 Nov 2013 08:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=bbA5JI3m2SJ1WfOQz+7cH+Igk1R4s5vQ1kjW9XKBjDs=; b=A/gL6sNQZ1OFM4x+4uGdP92R/FPDsBHDJfVyqbNUHYTnetR09R2zSJrTihf4ZKgF13 wW2jIHj+jMqo/f+cgUFP35xuG4CWnLfrMUoy8AwFTuF7Vv/ePx9JOCFUa9XYB5LxMa2+ liIyYxHoHQTY2mudcdwCzuGOsPmmhmpgtYT6monFAC5qIa/6CojdIfdQDPT40dQqbHjG cVkXiwskYCeZ3Y4t1/F4/VjOdGi+cPtGI8zGNDrG5hWLSIZdcHQN97ykC7Bsu4TSARPt VIm/uI/SEJPslVMLGD9nB5Ozk9MFZCq6IhCWNR/bTuqEtR7Q/MMBfvCd8syVs/D7DJVe +u7A== X-Received: by 10.204.54.136 with SMTP id q8mr133251bkg.100.1385396879056; Mon, 25 Nov 2013 08:27:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.122.72 with HTTP; Mon, 25 Nov 2013 08:27:17 -0800 (PST) In-Reply-To: <529370C0.9020801@gmail.com> References: <529370C0.9020801@gmail.com> From: Gabriel Scherer Date: Mon, 25 Nov 2013 17:27:17 +0100 Message-ID: To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com> Cc: "caml-list@inria.fr" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] [batteries] ... how to create (format) directives that do not take any arguments? Adding custom printing directives requires a syntax extension to rewrite those directives into OCaml code. The built-in support for magicly-typed formats in the OCaml language is not extensible (it is complex enough as it is). Batteries 1 used to provide such a syntax extension, but we (re)discovered that users don't like syntax extensions: they make code harder to compile/deploy, are controversial, and in the long run often make our life harder instead of easier. Batteries 2 does not come with any syntax extension, and I think we're better off as is (of course you're free to add your own in your code). Of course, such a natural idea is bound to be reused, and one of the first libraries released by J=E9r=E9mie Dimino at Jane Street was precisely such a custom-printf camlp4 extension: https://github.com/janestreet/custom_printf Feel free to reuse it or extend it for any project where it makes sense. In particular, I don't think that using it implies any dependency of your preprocessed code on Core, though of course you'll need Sexplib to use the format-to-sexplib feature. My purely personal advice would be to seriously explore non-syntax-extension approaches (combinator library?) before making such a step. On Mon, Nov 25, 2013 at 4:46 PM, Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote: > Dear all, > > I would like to define custom directives, that would enable me to write c= ode like e.g. this: > > Print.printf "regular %bold_on bold %bold_off regular %italic_on italic %= italic_off"; > > This might expand to (in HTML codes) > > regular bold regular italic > > or in ANSI codes to something analogous. > > I am currently looking at: > > http://ocaml-batteries-team.github.io/batteries-included/hdoc/BatPrint.= html > > It refers to: > > https://github.com/ocaml-batteries-team/batteries-included/blob/master/= examples/snippets/test_printf.ml > > Those things work, although there is no example for: > > Print.literal > > which might be (?) what I need to employ. > > Can somebody give me some advice how to create simple "parameterless form= at directives" (like those above)? > > ---- > > Basically, I just want to refactor some weird markup out of the literal s= tring while I do not want to reinsert the refactored stuff via %s because i= t is not maintainable. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs