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

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Tue Jun 10 11:10:13 EDT 2014

On 06/09/2014 06:38 PM, Stephen Chang wrote:
> Ok thanks.
>
> Is it accurate to say that the pattern in the #:with "shadows" the
> main pattern, as far as #:declare is concerned?

No, all pattern variables in a syntax-parse clause must be distinct. In 
particular, variables from a #:with clause must be distinct from the 
main pattern.

A sequence of #:declare clauses can occur only after the main pattern or 
a #:with clause, and they affect only the variables of that pattern.

> Can I add something that describes this behavior to the docs here: (or
> is it described somewhere else?)
> http://docs.racket-lang.org/syntax/stxparse-specifying.html?#%28tech._pattern._directive%29

Sure.

Ryan


> On Mon, Jun 9, 2014 at 5:00 PM, Ryan Culpepper <ryanc at ccs.neu.edu> wrote:
>> On 06/09/2014 02:40 PM, Stephen Chang wrote:
>>>
>>> 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?
>>
>>
>> It's the expected behavior. I'll try to improve the error message.
>>
>> Ryan
>>


Posted on the users mailing list.