Sew
#lang sew | package: sew-lib |
Sew is a Racket language that makes it easy to add boilerplate that surrounds the rest of the file, without changing its indentation.
#lang sew racket/base (require (only-in (racketmodname sew) 8<-plan-from-here)) [8<-plan-from-here <> #'(begin (provide main) (define (main) <> ...))] (displayln "Hello, world!")
The expression directly after the [8<-plan-from-here <>] line is evaluated in phase 1, with <> bound as a template variable to the rest of the content of the file.
This can come in handy for maintaining the file as though it belongs to a certain tradition of writing modules, while it actually belongs to another. For instance, the module above can be written as though it’s a script, but it’s actually a module that provides a main function.
In the Lathe project, we intend to use Sew to write a module once but compile it with multiple levels of contract enforcement.
For now, 8<-plan-from-here is the only directive defined by Sew. We might extend this in the future to allow files to be cut up into more than one piece before they’re all sewn together. This may resemble literate programming techniques for assembling programs in terms of chunks.
1 Sew Directives
syntax
[8<-plan-from-here rest-of-file-id preprocess-expr]
For instance, the usage site
[8<-plan-from-here <> #'(begin (provide main) (define (main) <> ...))] (displayln "Hello, world!")
expands into this:
(begin (provide main) (define (main) (displayln "Hello, world!")))