Not long after Knuth introduced literate programming, researchers in the field of functional programming languages devised an interesting variation on his idea, called "literate scripts". Interpreters for functional languages such as Miranda and Haskell accept literate scripts as well as ordinary programs.
The concept of a literate script is very simple: to encourage extensive commentary, the roles of comments and code are inverted. Any line that is not marked as code is assumed to be a comment. Every code line must be marked with the character ">" in its first column.
This is an example from the online Haskell manual, section 9.6. Notice that the authors boldly call this a "literate program", stretching Knuth's definition of the phrase at least as much as we do.
This literate program prompts the user for a number
and prints the factorial of that number:
> main :: IO ()
> main = do putStr "Enter a number: "
> l <- readLine
> putStr "n!= "
> print (fact (read l))
This is the factorial function.
> fact :: Integer -> Integer
> fact 0 = 1
> fact n = n * fact (n-1)
These lines are perfectly good input to the Haskell interpreter in exactly this form.
This is certainly a lightweight approach to producing well-documented code, and is quite similar in spirit to ours. We could easily apply the idea to other programming languages without modifying their interpreters or compilers, because it would be trivial to write a separate program to extract the code from a source file of this form; in fact, one such program would work for all languages. The biggest disadvantage that we see is that, in the end, all you have is an ASCII file. This may not be sufficient to satisfy a need for attractive, easy-to-read documentation with graphics, hypertext links, and the like. Again, we have an engineering tradeoff to consider.
But, if this were a concern, one could easily write a program that would read a literate script and insert markup into it to produce a document that looks much like one of our lightweight literate programs: the code set off in distinctive blocks, and the commentary in an attractive text font, formed into paragraphs around the code blocks.
It would be natural to treat empty lines within the commentary as paragraph breaks. And then one could use other conventions within the ASCII text to indicate other formatting or other document elements, as in (for example) Wiki markup notation. With enough of this markup added, literate scripts would be essentially the same as our lightweight literate programs! This shows that the two approaches are really just variations on the same theme.