Wednesday, July 20, 2011

Literate literate literate programming

In an effort to better document my Haskell experiments I wrote a set of reST directives for Sweave-like literate programming.

What makes rstweaver different from Sweave is that a single reST document can write and execute multiple source files, in stages, and parts can be inserted or modified, then reexecuted. This gives the illusion of an interactive session for a language that is largely not interactive.

If you look at the tutorial you will notice that it too includes literate reST... which in turn includes literate Haskell. It is literate literate programming!

And the society for putting things inside of other things demands that we go one level further: an excerpt from the tutorial: I present you literate literate literate programming:

-- so-nested.rst --

You can name the stages: .. weaver:: test4.rst exec block .. haskell:: Named.hs :name: imports import Control.Monad And then go back and edit them: .. weaver:: test4.rst exec block .. haskell:: Named.hs redo :name: imports import Control.Monad import Control.Applicative Or insert a stage after a named stage: .. weaver:: test4.rst exec block .. haskell:: Named.hs :after: imports x = 5

You can name the stages:

-- test4.rst --

.. haskell:: Named.hs :name: imports import Control.Monad

-- Named.hs --

1 import Control.Monad

And then go back and edit them:

-- test4.rst (cont) --

.. haskell:: Named.hs redo :name: imports import Control.Monad import Control.Applicative

-- Named.hs (cont) --

1 import Control.Monad 2 import Control.Applicative

Or insert a stage after a named stage:

-- test4.rst (cont) --

.. haskell:: Named.hs :after: imports x = 5

-- Named.hs (cont) --

4 x = 5

No comments:

Post a Comment