[plt-scheme] Escaping from Scribble examples

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Apr 6 15:03:11 EDT 2010

At Tue, 06 Apr 2010 14:19:54 -0400, David Van Horn wrote:
> In Scribble I can do this:
> 
> @(schemeinput (+ #,1 2))
> 
> But not:
> 
> @(examples (+ #,1 2))
> 
> Is there a way to escape to Scheme from the within the datum 
> subexpression of examples?

The problem is that the argument to `examples' is used both as code to
typeset (like `schemeinput') and an expression to evaluate (by putting
a quote on the front to form an argument in a call to `eval'). The #,
above does escape for the typesetting part, but it doesn't evaluate.

That is, with the document source

 #lang scribble/manual
 @(require scribble/eval)

 @examples[(+ #,1 2)]

I get the HTML output

  Example:
    > (+ 1 2)
    eval:1:0: unsyntax: illegal outside of quasisyntax in: (unsyntax 1)

My guess is that the solution to your problem involves a combination of
a macro over `examples' and using `eval:alts' to split the
`schemeinput' part from the part that's fed to `eval'. Maybe something
like this:

 #lang scribble/manual
 @(require scribble/eval)

 @(define-syntax-rule @my-examples[form ...]
    @examples[(eval:alts form (syntax->datum #`form))
              ...])

 @my-examples[(+ #,1 2)]



Posted on the users mailing list.