Examples of literate programming

Introduction

This page contains PDF versions of some literate programs by Donald Knuth, posted on his webpage at https://cs.stanford.edu/~knuth/programs.html. Most of them are in the CWEB system, in which the programmer (Knuth in this case) writes a .w file, which is processed either:

Prof. Knuth has posted the .w files on his webpage, but I’m afraid that many casual readers may not take the time to install cweave and tex, and thus may try to read the .w file directly. So here I’ve put the typeset versions for convenience.

This is the note on his website:

I write lots of CWEB programs, primarily for my own edification. If there is sufficient interest, I’ll make a large subset of them available via the Internet. For now, I’m listing only a few. […]

He also adds a note that many of the programs “use the conventions and library of The Stanford GraphBase”.

Here are the programs as listed on his webpage, with the .w and .ch links changed to corresponding .pdf files (from running cweave and typesetting them). There may be some errors in the conversion; let me (Shreevatsa) know. (Several “I”, “my” etc. below refer to Prof. Knuth, as the list is copied from his webpage.)

CWEB programs