[plt-scheme] problems with scribble/text language

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jun 24 14:31:03 EDT 2008

On Jun 24, Richard Cobbe wrote:
> I'm having some difficulty with the scribble/text language in
> 4.0.1.1 and I hope someone can suggest a way to proceed.  Here's the
> basic structure of my problem.  Simple scribble/text document,
> test.ss:
> 
>     #lang scribble/text
>     @(define (foo x y) (format "foo: x = ~a; y = ~a" x y))@;
>     blah
>     @foo[3 4]
>     blah
> 
> This works as I expect; when I run "mzscheme test.ss", I get the output
> 
>     blah
>     foo: x = 3; y = 4
>     blah
> 
> All well and good.
> 
> But I'm having problems when one of the arguments to foo is itself
> in text mode.  I know that @{...} treats the stuff inside the
> brackets as text, but this doesn't fit into the larger expression:
> 
>     @foo[@{\three} 4]
> 
> gets read as
> 
>     (foo ("\\three") 4)
> [...]

A common solutions that I use is to dump things into a function:

  @foo[@string-append{\three} 4]

that works better when you have a shorter name for `string-append'.
But another option is to just use pairs as a general device for
concatenation, which means that you can use

  @foo[@list{\three} 4]

or

  @foo[@'{\three} 4]

the second one is read as '("\\three").  But note also that the
scribble/text language uses pairs for the same purpose, so you  caan
use something like this:

  #lang scribble/text
  @(define (foo x y) @list{foo: x = @x; y = @y})@;
  blah
  @foo[3 4]
  @foo[@list{\three} 5]
  blah




> So I tried the following instead:
> [...]

BTW, unrelated -- but, with macros you can get much more sophisticated
things going on, using the scribble syntax properties.


> I tried splitting this into two files (which was the way I had it before I
> tried to find a minimal test case), and I get different behavior.
> 
> test-funs.ss:
>     #lang scheme
>     (define (foo* x y) (format "foo: x = ~a; y = ~a" x y))
>     (define-syntax (foo stx)
>       (syntax-case stx ()
>         [(foo ((arg ...) ...))
>          #'(foo* (list arg ...) ...)]))
>     (provide foo)
> 
> test.ss:
>     #lang scribble/text
>     @(require "test-funs.ss")
>     blah
>     @foo[@{\three} 4]
>     blah
> 
> And now, running 'mzscheme test.ss' gives me
> 
>     test.ss:4:0: foo: bad syntax in: (foo ("\\three") 4)
> 
> so it looks like macro expansion isn't happening here.

It does, but you got the syntax pattern wrong...  With this wrong
template, this would work:

  @foo[(@{\three} (4))]

...but you probably want to change the template...

...but you probably don't need any of the macro stuff anyway...

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


Posted on the users mailing list.