Hi everyone,

Thanks for the numerous replies. There are a lot of good solutions in there, 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 example in the examples/ directory that used another language, such as OCaml. I guess that's because it's still in development?
- rwo-run-toplevel seems closer to what I have in mind; if I could send all the ocaml parts to a top-level session, and put in my document what gets sent to stdout (not the toplevel reply, that is, not the "val f: int -> int" parts), that would be pretty much all I need. rwo-run-toplevel seems to perform a lot of work, though: what are all these rewrite rules?

Other solutions seemed interesting. The Perl script scared me a little bit; being no Perl hacker, I would have a hard time using it. The Markdown library does not seem to be an exact fit (I want the output of arbitrary OCaml commands to be put in the middle of my markdown.) Stog seems to be oriented towards reproducing an interactive toploop session, while I'm more interested in executing arbitrary commands. Alain's sed trick seems to be exactly what I need, I'm just a bit afraid if I ever need to change something, it'll be break. But in essence, yes, that's just all I need. Other proposals seemed a little bit too far away from what I had in mind.

Thanks again for the replies!
~ jonathan
On 09/02/2013 06:29 PM, Ashish Agarwal wrote:
OCaml Labs is developing MPP (Meta Preprocessor) [1]. It will be used in a new implementation of ocaml.org [2], which includes pages like 99 problems [3] that are generated by running ocaml code through the toploop. In case blah = Markdown, please also note the new Markdown library [4].

[1] https://github.com/pw374/MPP-language-blender
[2] http://lists.ocaml.org/pipermail/infrastructure/2013-July/000211.html



On Mon, Sep 2, 2013 at 11:39 AM, Jonathan Protzenko <jonathan.protzenko@gmail.com> wrote:
Hi,

I am currently writing a big, mostly textual document in format blah
(blah being of a course a meta-variable). Are there any tools that
would allow me to interleave OCaml code with the contents of my
document?

More on my use-case. Creating this document requires me to perform
various subtasks, such as:
- write a code snippet in the document,
- put the code snippet in a file,
- call an external program on the file,
- paste the output into the document.

Naturally, I wish to automate this. I could roll my own set of
commands, and parse them with OCaml, but I would be re-creating a
scripting language, and it seems to me that interleaving OCaml code
within my document would be better. Here's what I have in mind:


blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah
blah ... we thus write the following code ... :

{%
  let code = "<sample code>" in
  output code
%}

blah blah blah ... after running the command blah ... the output is as
follows ... blah

{%
  let f = write_into_temp_file code in
  let s = run_and_read "myprogram" [f] in
  output s
%}

blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah ...


Are you aware of any tool that would allow me to achieve this?

Thanks,

~ jonathan

--
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