[plt-scheme] problems with scribble/text language

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Tue Jun 24 14:12:16 EDT 2008

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)

and of course this fails during evaluation:
    procedure application: expected procedure, given: "\\three" (no arguments)

So I tried the following instead:

    @(define (foo* x y) (format "foo: x = ~a; y = ~a" x y))@;
    @; the following inserts blank lines, but I don't care for now.
    @(define-syntax (foo stx)
       (syntax-case stx ()
         [(foo ((arg ...) ...))
          #'(foo* (list arg ...) ...)]))
    blah
    @foo[@{\three} 4]
    blah

and then running 'mzscheme test.ss' gives me

    test.ss:5:3: compile: bad syntax; function application is not allowed, because no #%app syntax transformer is bound in: (syntax-case stx () ((foo ((arg ...) ...)) (syntax (foo* (list arg ...) ...))))

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.

Is there a way to do this without having to explicitly quote all of foo's
arguments?

Thanks,

Richard


Posted on the users mailing list.