λの花

promiscuous programming

Literate Racket

I started messing around with literate programming in Racket recently using the Scribble tool. I had a little trouble getting the basic example working, because you need a base Scribble document in addition to the literate program file:

Base Scribble Documentindex.scrbl
1
2
3
4
5
6
7
#lang scribble/base

@(require scribble/lp-include)

@title{Fizzbuzz in Literate Racket}

@(lp-include "fizzbuzz.scrbl")

Once this template is set up the main program can be written in fizzbuzz.scrbl:

Main Programfizzbuzz.scrbl
1
2
3
#lang scribble/lp

...

Finally, to compile with cross-reference links correctly it is necessary to use, scribble +m --redirect-main http://docs.racket-lang.org/ index.scrbl. As +m links against local documentation by default --redirect-main is used to point to the main racket site.

Here’s the final output.