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

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

Ok thanks.

Is it accurate to say that the pattern in the #:with "shadows" the
main pattern, as far as #:declare is concerned?

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

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.