[racket-dev] New error messages for *SL

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 7 07:21:46 EDT 2011

I've clarified with Mike the problem, and that email.  For reference,
that email had a macro that had some complication in that it
implemented a raw `include' with scribble syntax -- but putting the
code inside a scribble file makes that unnecessary.

So there are two problems: the first is that he wants to use
identifiers in the documentation-generating macro that depend on the
lexical context where the macro is used.  In other words, he wants to
use a macro that breaks hygiene... which means that something like
this should work for that purpose:

  (define-macro (foo x . body)
      Blah blah blah, @racket[x], blah blah.
      @, at body})    ; <-- "@" is for scribble, ",@" is as usual

Or even better, just avoid the `define-macro' guessing of context at

  (define-syntax (foo stx)
    (syntax-case stx ()
      [(_ x body ...)
       (with-syntax ([x (syntax->datum #'x)]
                     [(body ...) (syntax->datum #'(body ...))])
             Blah blah blah, @racket[x], blah blah.
             @|body ...|})]))    ; <-- have `body' followed by `...'

(Funny that it's a similar kind of breakage that the literate
programming thing is doing.)

The other problem is that he wants the macro to generate a section
too, with references, which means that each use needs to generate
different tags.  Instead of fighting with some gensym, what I
suggested earlier is to have some part of the tag be an input to the
macro, so it ends up like

  (define-syntax (foo stx)
    (syntax-case stx ()
      [(_ tagpart x body ...)
       (with-syntax ([x (syntax->datum #'x)]
                     [(body ...) (syntax->datum #'(body ...))]
                     [tag (format "foo-~a" (syntax->datum #'tagpart))])
             Blah blah blah, @racket[x], blah blah.
             @subsection[#:tag tag]{Some Title}
             More blah blah blah.
             @|body ...|})]))

(Warning: I'm too tired to actually try the above... so it's

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.