Literate Programming Examples from my Website

Menu

I have become rather interested in literate programming, which I find a very interesting and elegant approach. Literate programming was first proposed by Donald Knuth and it is supported very well by Emacs: consult the Org Mode manual for more information.

This page lists the pages of this website which use literate programming.

The first version has a list compiled by hand… I then realized I could be more efficient and precise by using code to extract the information and this page has become itself an example of literate programming.

First of all, we find all occurrences of #+BEGIN_SRC in the source files (with the exception of this file) which are required to produce results. We use sed to process the output, using a TAB to separate the filename from the content and by extracting the programming language, which is the first word after #+BEGIN_SRC.

grep BEGIN_SRC $(find ../.. -name "*.org" -a \! -name literate-programming-references.org ) | grep results | grep -v "_site" | sed 's/:/\t/' | sed -E 's/#\+BEGIN_SRC +([^ ]+) .*/\1/' 

The output, which is not exported, looks like:

| ../../bookstream.org                                    | ruby    |
| ../../notes/covid/new-cases.org                         | R       |
| ../../notes/covid/new-cases.org                         | ruby    |

We now use datamash to make the data into a Pivot table, with the crosstab command. Sed is used to generate links to the files, by prepending file: to the filenames and to remove the “N/A” entries.

echo "$table" | sort | datamash crosstab 1,2 | sed 's-N/A--'g | sed -E 's/\.\./file:../' 
0

Author: Adolfo Villafiorita

Last modified: 2020-08-28 Fri 21:06 (created on: 2020-06-02 Tue 00:00)

Published: 2020-12-04 Fri 13:20