[racket] syntax-parse #:with directive followed by #:declare

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Mon Jun 9 14:40:45 EDT 2014

This program:

#lang racket
(require (for-syntax syntax/parse))

(define-syntax (test stx)
  (syntax-parse stx
    [(_ x)
     #:with y #'x
     #:declare x expr
     #'x]))

produces the error:

syntax-parse: declared pattern variables do not appear in pattern in:
  (syntax-parse stx ((_ x) #:with y (syntax x) #:declare x expr (syntax x)))
  x

With the #:with, the #:declare no longer sees the x variable. The
error goes away if the #:with and #:declare are flipped. I extended
the example with more variables and it seems like #:declare only sees
the variables in the #:with pattern and not the main pattern.

Is this a bug or expected behavior?

Posted on the users mailing list.