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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id EC6B5820A1 for ; Tue, 3 Sep 2013 16:34:13 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.wang.lists@gmail.com) identity=pra; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.wang.lists@gmail.com designates 74.125.82.45 as permitted sender) identity=mailfrom; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="philippe.wang.lists@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f45.google.com) identity=helo; client-ip=74.125.82.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.wang.lists@gmail.com"; x-sender="postmaster@mail-wg0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUBALPyJVJKfVItjWdsb2JhbABbgzxRwHWBIggWDgEBAQEHCwsJEgYkgiQBAQUnGQE4AQMMAQUFCw0uIQESAQUBHAYTG4dVAw+be49VhEAnDYhLAQUMjH2BNIEGhFcDjmSHKIFpjDeDRhgpgWGCaDuBNQ X-IPAS-Result: AtUBALPyJVJKfVItjWdsb2JhbABbgzxRwHWBIggWDgEBAQEHCwsJEgYkgiQBAQUnGQE4AQMMAQUFCw0uIQESAQUBHAYTG4dVAw+be49VhEAnDYhLAQUMjH2BNIEGhFcDjmSHKIFpjDeDRhgpgWGCaDuBNQ X-IronPort-AV: E=Sophos;i="4.89,1014,1367964000"; d="scan'208";a="31338608" Received: from mail-wg0-f45.google.com ([74.125.82.45]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Sep 2013 16:34:13 +0200 Received: by mail-wg0-f45.google.com with SMTP id y10so4777650wgg.12 for ; Tue, 03 Sep 2013 07:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=CKeEJCbXfkq4sBr8MK2Uwl2dde/ptsZTUrhlj+iQQBg=; b=bkysIJlPljrvIRCUb0BWBFhHBglOaVWj3sMemIRVb0TarJpWlyWCVFrip2uaJjfT1Z nd6NDwVk/jyqzQEVGbl8JYety1TdMejwNfOIKCyTkJpLyYgn+uxw/NAly8RSCFMkXcO2 oRt3T9lCHhXfHIFSdjijMpGiBDmFz14gAdJv9wy1igpSMROmaWJ6nbf3+tspmfkROHqw V1OkcTWKzo3jRQdK1bjNeRxI9r3gJ6wSNoN8qAym9xuUW2ULIRge9gxDwkDyInNQ84zd F0cu6SkiUyp9ilA42tJmFQHTGXpHCMlCOqgAXdGHBpxptf9sNAu7ypi5G+P1TxlB8YLr g3pQ== MIME-Version: 1.0 X-Received: by 10.180.108.2 with SMTP id hg2mr18417719wib.7.1378218853309; Tue, 03 Sep 2013 07:34:13 -0700 (PDT) Sender: philippe.wang.lists@gmail.com Received: by 10.216.42.134 with HTTP; Tue, 3 Sep 2013 07:34:13 -0700 (PDT) In-Reply-To: <5224F20C.1010905@gmail.com> References: <5224B137.8070706@gmail.com> <5224F20C.1010905@gmail.com> Date: Tue, 3 Sep 2013 15:34:13 +0100 X-Google-Sender-Auth: qP6o9QeXDb-uXcrJ6hYOu0MNURM Message-ID: From: Philippe Wang To: Jonathan Protzenko Cc: Ashish Agarwal , Caml List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Literate (sort-of) programming in OCaml On Mon, Sep 2, 2013 at 9:16 PM, Jonathan Protzenko wrote: > Hi everyone, > > Thanks for the numerous replies. There are a lot of good solutions in the= re, > and the ones that looked closest to what I had in mind seem to be MPP and > the rwo-run-toplevel script. Some questions about these two tools: > - MPP seems to just have the built-in language. I couldn't find any examp= le > in the examples/ directory that used another language, such as OCaml. I > guess that's because it's still in development? Hi, MPP currently has 2 things: the built-in language and its commands, and the ability to bring OCaml as a pre-processor language. With mpp -its (-its is an option to be less strict on trailing spaces in commands) : ((x cmd ocamlopt foo.ml x)) will execute "ocamlopt foo.ml" in a shell and input its output. Note that "x" is the name of the block. It could be FOO or 23NUI'=E8!=E7=E9 instead, so that one can write ((x cmd echo $((42+42)) x)) for instance without being bothered by escaping stuff. -> This is an example of the builtin commands. To have the list of built-in commands: mpp -b One may want to nest mpp commands. In this case, another pair of tokens is used: {{ and }}. so ((x cmd ocamlopt foo.ml x)) could be written {{x cmd ocamlopt foo.ml x}} instead. In this precise case, there is absolutely no difference. However, one can also write {{x cmd ocamlopt {{y get filename y}} x}} or {{x cmd ocamlopt ((y get filename y)) x}}. But if one write ((x ocamlopt ((y get filename y)) x)) then a shell will try to run "ocamlopt ((y get filename y))", which is probably not what's intended... All tokens of the language provided by mpp are customisable on the command line and live in mpp as well. mpp -so 42 will use "42" instead of "((" to open blocks. (( so TOTO)) will use TOTO to open blocks after this one, meaning that to set the open token back to what it was, one could write TOTO so (()) Well, it's up to the user to imagine how powerful it is. Then, there is the ability to bring ocaml as a pre-processor language. This is actually the main motivation for mpp. Sometimes, you write something using a specific language and you just wish you could easily use OCaml (or another language...) to preprocess your file. With mpp, the default tokens are {< and >} to embed ocaml. This means that in any file, one can write ocaml and have its output. Small example in markdown: If you write this in the file e.md ``` # Number of the day {< let foo =3D 42 >} The number of the day is {< let () =3D Printf.printf "%d" foo >}. ``` And you run mpp -l ocaml over e.md (note the -l option), then you obtain ``` let _ =3D print_string "# Number of the day\n\n" let foo =3D 42 let _ =3D print_string "\nThe number of the day is \n" let () =3D Printf.printf "%d" foo let _ =3D print_string ".\n\n" ``` which is an ocaml programme that you can run to have your final document: ``` # Number of the day The number of the day is 42. ``` You can see that the environment is shared. If you want different environments, it's possible to run mpp several times with different opening and closing tokens. Of course, you may use ocaml as a preprocessor language in an ocaml programme (instead of a markdown document), or any textual file actually. For the moment, ocaml is the only option supported by "mpp -l" but I'll provide more language soon. (To provide a language X, one has to write a "description" of how to convert a text file into an X programme.) I've not written much documentation for MPP yet because I've been mainly working on OMD, a Markdown->HTML converted and Markdown parser library in OCaml. Now I believe OMD is nearly done, so I'm getting back to MPP soon... --=20 Philippe Wang mail@philippewang.info