next up previous
Next: Writing Documentation for LPS Up: Designing and Documenting Individual Previous: Basic Concepts of Literate

Writing Code for LPS

  Most LPS treat the file as primarily one of text information; if nothing special is done, the tangle program would find nothing to send to a compiler. Code chunks are begun by a chunk name and terminated by some special mark. In noweb, the special mark is the ``at'' symbol, `@'. The chunk name is a bit more complicated. It normally is a bracketing convention that is used to quote a string that is the name of the chunk. In noweb, the rules are simple: the name has a form <<anything>>= with the << starting in column 1. noweb assumes that there is a chunk name of *. Therefore, the simplest file that would work might look like Figure 6

   table202
Table 6: Simple noweb File

The <<name>> marker can be associated with many different code chunks. This is particularly useful when the code is described in a top down fashion. For example, in Figure 7 we see the mixing of document chunks with code chunks using this feature. The compiler sees the same input regardless.

   table213
Table 7: A Bit More Complex noweb File

Notice that ``stdio.h'' is in a different font from the rest of the words in the comments. This is accomplished by writing ``double-brackets'' around stdio.h as [ [ stdio.h ] ]. This allows us to use fonts to draw attention to program names and expressions in the documentation. This is similar to the rules used to typeset mathematics.

The last feature to describe is how to use the definitions. Figure 8 shows a much rearranged version of Figure 7. Now we have given the two code chunks distinct names, neither of which is *. To get the output to the compiler, we invented a new code chunk for the * and put the names of the code chunks in their proper order.

These simple procedures are all one needs to know to make effective use of a simple LPS.

   table233
Table 8: An Even More Complex noweb File


next up previous
Next: Writing Documentation for LPS Up: Designing and Documenting Individual Previous: Basic Concepts of Literate

Steve Stevenson
Wed Feb 26 10:54:45 EST 1997