3

I've a library project which requires C's interoperability with other languages, and reasonable performance, but must be documented very clearly, à la literate programming, and whose documentation might benefit from a functional approach, like Haskell, or even Idris' proof features.

I'm therefore interested in building this library as a literate program, first writing the documentation and working Idris prototype code, and next writing C code that closely parallels the Idris code to address any performance issues and be easily linkable from other languages.

What literate programming tool do I want?

NuWeb is designed for multi-language literate programming, but their usage of the @ sign, or indeed any escape character, is problematic for functional languages like Idris, Haskell, etc.

Idris wants a literate programming tool to which I could contribute. I love their preferred approach of just using .tex files delimited by \begin{code} .. \end{code} blocks.

Idris, Haskell, etc. do not need tangle like C does, so doing that adds complexity and I'd prefer that any tool I'm using here sticks around.

An approach that minimizes tooling for library consumers might be to extract the C and Idris code using a simple Perl script like cat_latex_env:

#!/usr/bin/perl
use strict;
use warnings;

sub usage { die "Usage: cat_latex_env enviroment_name [filename]\n"; }
usage if ($#ARGV < 0);

my $env = shift;
my $begin = quotemeta "\\begin{$env}";
my $end = quotemeta "\\end{$env}";
while (<>) {
        if (/$begin/../$end/) {
                next if /$begin/ || /$end/;
                print;
        }
}

At which point the Idris should compile fine. And I could embed the tangle instructions needed by a literate programming tool for C like CWEB or NuWeb.

Thoughts?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jeff Burdges
  • 4,204
  • 23
  • 46
  • I would not create an answer, as my option is biased. Personally, I'm against any form of literate programming, it makes program maintenance and debugging pretty hard. I would suggest you to look at the other way around, using document tools inside the program. like doxygen for C and http://en.wikipedia.org/wiki/Haddock_(software) for Haskell, etc. – qunying May 05 '15 at 17:43
  • @Cœur This question seems off-topic as it is asking for software recommendations. Your edit was just correcting one spelling mistake. Would you have served Stack Overflow better by voting to close this question? – AdrianHHH Apr 03 '17 at 08:14
  • @Cœur to add to what AdrianHHH said: the problem is mainly that this question was bumped to the front page, without significant improvement (I don't count one spelling correction as significant) and that now this OT question gets renewed attention due to it being on the front page again. I've seen you edit questions with insignificant edits like this only to be closed not much later; please take the bumping of a question into account when editing and consider whether close voting wouldn't be the better option. – Adriaan Apr 03 '17 at 08:22
  • @AdrianHHH I count spelling corrections as significant. It's good that people vote to close if they figure out it's off topic: I don't always notice, but when I do I downvote and vote to close too. – Cœur Apr 03 '17 at 10:14

1 Answers1

1

If documentation is paramount, and you have some emacs affinity, then you might do worse than look at the literate programming support in org-mode. Babel is an org-mode extension allowing to integrate with many programming environments, including tangle-weaving compiled languages, executing code blocks, ...

It is thoroughly language agnostic, and since it has the DNA of an outliner, it allows to manage the documentation in a structured way. Of course it generates syntax highlighted HTML/LateX/PDF/... from your sources.

Check out http://orgmode.org/worg/org-contrib/babel/intro.html for more info.

a sample:

** Compiles libpq library for iOS

copy this script as *build-ios.sh* in the root of the postgresql
source tree.

#+BEGIN_SRC sh tangle:build-ios.sh
mkdir -p build
rm -rf build/* #*/

function build_libpq()   
{
    make distclean

    ./configure \
...snip...
lipo -create -output libpq.a build/*

#+END_SRC

Run it and it will create a universal library and  separate arm  
library in the root folder.

I hope this gives an idea what to do to create docs/code using org-mode/Bable combination. Of course a stackexchange answer cannot begin to scratch the surface of this system.

Jonathan Jin
  • 485
  • 1
  • 3
  • 15
Peter Tillemans
  • 34,983
  • 11
  • 83
  • 114