[racket-dev] Dotted syntax/parse patterns and scribble/eval

From: Casey Klein (clklein at eecs.northwestern.edu)
Date: Wed Sep 21 17:39:00 EDT 2011

I'm confused by the behavior of syntax/parse pattern variables that
come after dots. Sometimes they're bound to lists and sometimes to
syntax objects.

For example, in the following example, the variable `after-ones' gets
bound to a list:

   #lang racket/base

   (require (for-syntax racket/base))

   (begin
     (require (for-syntax syntax/parse))

     (define-syntax (m stx)
       (syntax-parse stx
         [(_ 1 ... . after-ones:expr)
          (if (list? #'after-ones)
              #''list
              #''not-list)]))

     (m 1 1 2 1 2 3)) ; 'list

but it gets bound to a syntax object if I drop the variable's `expr'
syntax-class.

That is, unless you're using scribble/eval, in which case dropping the
syntax-class does not change the behavior:

   #lang scribble/manual

   @(require scribble/eval)

   @(parameterize ([current-eval (make-base-eval)])
      (interaction-eval (require (for-syntax racket/base)))
      (interaction (begin
                     (require (for-syntax syntax/parse))

                     (define-syntax (m stx)
                       (syntax-parse stx
                         [(_ 1 ... . after-ones:expr)
                          (if (list? #'after-ones)
                              #''list
                              #''not-list)]))

                     (m 1 1 2 1 2 3))))

What's going on?


Posted on the dev mailing list.