This example is written in a style of literate programming (Knuth 1984). The combined code-blocks in this example compose a compilable source code for “Hello World”. For didactic reasons we don’t always give the listing of an entire source file in one go. In stead, we use a system of references known as noweb (Ramsey 1994).

Inside source fragments you may encounter a line with <<...>> marks like,

«hello_world.cc»=

#include <cstdlib>
#include <iostream>

<<example-main-function>>

which is then elsewhere specified. Order doesn’t matter,

«hello-world»=

std::cout << "Hello, World!" << std::endl;

So we can reference the <<hello-world>> code block later on.

«example-main-function»=

int main(int argc, char **argv) {
  <<hello-world>>
}

A definition can be appended with more code as follows (in this case, order does matter!):

«hello-world»+

return EXIT_SUCCESS;

These blocks of code can be tangled into source files.

References

Knuth, Donald Ervin. 1984. “Literate Programming.” The Computer Journal 27 (2): 97–111.

Ramsey, Norman. 1994. “Literate Programming Simplified.” IEEE Software 11 (5): 97–105.