[racket] Add an implicit (require (for-doc ...)) via a #lang

From: Michael Ballantyne (michael.ballantyne at gmail.com)
Date: Thu Dec 5 18:21:25 EST 2013

Hello all,
I'm implementing a module language. All modules using the language
will be using Scribble's in-source documentation. It's easy enough to
have the module language provide

(all-from-out racket/contract scribble/srcdoc)

but I haven't figured out a way to avoid having each module have the lines

(require (for-doc racket/base
          scribble/manual))

One thing I've tried is adding that require form to the top of modules
using the language via #%module-begin. The code I used for that is
below:

#lang racket/base

(require
 racket/contract
 scribble/srcdoc
 scribble/manual
 )

(provide
 (except-out (all-from-out racket/base) #%module-begin)
 (rename-out
  [module-begin #%module-begin])
 (all-from-out
  racket/contract
  scribble/srcdoc)
 )

(module reader syntax/module-reader
  #:language 'doctest)

(define-syntax-rule (module-begin a ...)
  (#%module-begin
   (require
    (for-doc
     racket/base
     scribble/manual))
   a
   ...
   )
  )

Then testing with this file:

#lang at-exp doctest

(define (testfun a)
  a)

(provide
 (proc-doc/names
  testfun
  (-> any/c any/c)
  (a)
  @{Doc test}
  )
 )

I receive this error:

?: literal data is not allowed;
 no #%datum syntax transformer is bound in: "Doc test"

Examination with the macro stepper in Dr. Racket suggests the
module-begin syntax rule is working as expected, but the (require
(for-doc ...)) that is added somehow doesn't behave like one that was
originally the module does.

Any ideas on what might be going wrong or on a better way to achieve this?

Thanks!

Posted on the users mailing list.