[plt-scheme] problems with scribble/text language

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

On Tue, Jun 24, 2008 at 02:12:16PM -0400, Richard Cobbe wrote:

Never mind, figured it out.

<SNIP>

>     @(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 ...) ...))))

Sam suggested adding

    @(require (for-syntax scheme/base))

which does indeed solve the #%app error.  Leaves the second one, though,
but that's my problem:

> 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.
>

Macro expansion is happening, but my pattern doesn't match the use.
Replacing the definition of foo with

    (define-syntax (expand-arg stx)
      (syntax-case stx ()
        [(expand-arg (arg ...))
         #'(list arg ...)]
        [(expand-arg arg) #'arg]))
    (define-syntax (foo stx)
      (syntax-case stx ()
        [(foo arg ...)
         #'(foo* (expand-arg arg) ...)]))

works; the file now produces

    blah
    foo: x = (\three); y = 4
    blah

And I can get rid of the extra parens around \three easily enough.

Richard


Posted on the users mailing list.